I need to create an Android horizontal layout design with a vertical LinearLayout on the left and a TextView on the right, as shown below:
¦==========================¦
¦ A1 ¦ ¦
¦ ¦ BB ¦
¦ A2 ¦ ¦
¦==========================¦
The vertical LinearLayout on the left contains two TextView elements and sections A and B take the entire screen width. All TextView elements contain dynamically assigned text content.
I want the width of the TextView B to be determined by its content so that it expands or shrinks to show its entire content (which can’t wrap and must be shown in a single line), while the width of the LinearLayout A on the left is to be determined by the width of TextView B, as shown below:
TextView B expands:
¦==========================¦
¦ A1 ¦ ¦
¦ ¦ BBB ¦
¦ A2 ¦ ¦
¦==========================¦
TextView B shrinks:
¦==========================¦
¦ A1 ¦ ¦
¦ ¦ B ¦
¦ A2 ¦ ¦
¦==========================¦
My idea was to use a LinearLayout like this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/A1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/A2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
but with the above layout, if the content of TextView A1 is long enough, it takes the whole screen width and TextView B disappears.
Any ideas?
You should make the right textview to wrap content and make the left linearlayout use the weight attribute as
This will tell the linearlayout to take the remaining space. But if the text is too long, either reduce the size of the text or elipsize.