How can I achieve the next layout when the TextView is TextViewwith an end with an ellipsis and a view wrap_contentand immediately to the right of the TextView?
Here are three examples of how the layout should look, with different widths of the TextView:
|[TextView] [View] |
|[TextView TextView] [View] |
|[TextView TextView T...] [View]|
[edit]
The following TableLayoutgives the correct behavior:
<TableLayout
android:id="@+id/upper_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/alert_button"
android:shrinkColumns="0"
android:stretchColumns="2" >
<TableRow>
<TextView
android:id="@+id/name_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:includeFontPadding="false"
android:lines="1"
android:paddingTop="2dp"
android:scrollHorizontally="true" />
<TextView
android:id="@+id/unread_count_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:includeFontPadding="false"
android:paddingBottom="0dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="2dp" />
</TableRow>
</TableLayout>
TableLayoutuses 3 columns, the last of which is a hack: the property strechColumnsforces all the free space, so the second is TextViewalways to the right of the first. The first TextViewellipsis is correct due to the property shrinkColumns.
However, I do not like the idea of ββusing TableLayoutto achieve this. Does anyone know a better way?
thank
source