views:

550

answers:

2

Hi,

Currently I'm working on a dialog which consists of title, description, tags and footer. The title can be long and in this case the text should automatically be displayed in multiple lines. The description is also longer and should fill multiple lines. At the bottom of the dialog has to be the footer (also if the title and description don't fill whole screen). I tried to do create the layout described about but had a problem with long text - if the content is long it doesn't display multiple lines but extends main view (LinearView) so the content extends over the visible area.

Here I'm pasting the print screen of the current state and the mockup of the desired layout: alt text alt text

TextView "Footer" and buttons OK and Cancel should appear at the bottom of the screen and the title ("Title Title Title...) and description text should automatically appear in multiple lines instead of extending the parent view.

I would really appreciate if anyone of you could give a tip about solving these layout issues.

Thanks!

A: 

Are you using Eclipse? Try using TableLayout and TableRows, and setting Gravity properties. It takes a bit of playing around with to get right.

Tom R
+1  A: 

Something like this should help: placing the text elements up top, and forcing the buttons to the bottom of the layout using weightSum. I can't remember the settings for multi-line text offhand, but if you're not using the singleLine attribute set to true, then things should work out ok.

Check the XML attribute documentation for more info.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:weightSum="1">

  <TextView
    android:id="@id/android:title"
    android:layout_width="fill_parent"
    android:layout_weight="1" />

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="2">
      <Button
        android:id="@+id/btn_ok"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="@string/btn_ok" />
      <Button
        android:id="@+id/btn_cancel"            
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:text="@string/btn_cancel" />
  </LinearLayout>

</LinearLayout>
Christopher
I was just about to post a similar layout question and found this. I haven't seen weightSum attribute before this, but that's exactly what I needed. Thanks!
Rich