Android - ellipsis with proper alignment

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

+5
source
2

( , , , ):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="6dip" >

    <TextView
        android:id="@+id/my_txtvw_txtvw"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:ellipsize="marquee"
        android:maxLines="1" />

    <TextView
        android:id="@+id/my_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/my_txtvw_txtvw"
        android:maxLines="1" />

</RelativeLayout>
0

:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/text1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/my_view"
        android:ellipsize="end"
        android:maxLines="1"
        android:layout_alignParentLeft="true"
        android:text="blablabla blablabla"
        android:layout_centerVertical="true"
        android:gravity="center_vertical|left" />

    <TextView
        android:id="@+id/my_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:maxLines="1" />

</RelativeLayout>

, android:ellipsize="end" android:ellipsize="marquee". , , .

...

0

All Articles