I want to have two TextView
elements appear side by side (in a list item), one aligned to the left, one to the right. Something like:
|<TextView> <TextView>|
(the |
represent the screen's extremities)
However, the TextView
on the left can have content that is too long to fit on the screen. In this case, I want to have it ellipsize but still show the entire right TextView
. Something like:
|This is a lot of conte...<TextView>|
I have had numerous attempts at this, using both LinearLayout
and RelativeLayout
, and the only solution I have come up with is to use a RelativeLayout
and put a marginRight
on the left TextView
big enough to clear the right TextView
. As you can imagine, though, this is not optimal.
Are there any other solutions?
Final, LinearLayout
solution:
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:inputType="text"
/>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:layout_gravity="right"
android:inputType="text"
/>
</LinearLayout>
Old, TableLayout
solution:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:shrinkColumns="0"
>
<TableRow>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
/>
<TextView android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="none"
android:gravity="right"
/>
</TableRow>
</TableLayout>