views:

87

answers:

1

If you have two TextViews side by side each with a varying number of lines and then want a TextView below both of these how would you implement it?

For example, if you had:

<TextView
  android:id="@+id/textview1"
  android:layout_width="160dip" 
  android:layout_height="wrap_content"

  android:layout_alignParentLeft="true"
  android:maxLines="5" />

<TextView
  android:id="@+id/textview2"
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"

  android:layout_toRightOf="@id/textview1"
  android:maxLines="5" />

and then wanted a TextView to be below both of these (but as high as possible), its instinctive to try:

<TextView
  android:id="@+id/textview3"
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content"

  android:layout_below="@id/textview1"
  android:layout_below="@id/textview2" />

But clearly you can't have duplicate attributes. So how would you do it (or do you have to resort to doing it in code?)

A: 

I wound wrap TextView 1 and TextView 2 in a RelativeLayout, as follows:

<LinearLayout>
  <RelativeLayout>
    <TextView 1/>
    <TextView 2/>
  </RelativeLayout>
  <TextView 3/>
 </LinearLayout>

the point is that you could wrap views/viewgroups with view groups, i.e. RelatvieLayout/LinearLayout

Andy Lin
Fantastic, cheers.
The Salt