开发者

a layout with ellipsis then a counter

I'm new to Android, please help me to design below layout. Many thanks.

I want to implement a layout, it shows a text followed by a counter. If the text is too long, show ... followed by counter. like below:

Expected layout:

Short text (3) // when screen width is enough

Lo开发者_JAVA百科ng text blah bl...(2) // when screen width isn't enough

Below are my xml. It shows normally for above 1, when text is short. When text is long, the problem are: 1) it doesn't show "..." at the end of text 2) counter (2) isn't shown on screen.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:layout_weight="1" 
    >

    <TextView android:id="@+id/text" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="very long body safbadaf asfasf safasfd"
        android:layout_gravity="left"
        android:paddingLeft="4dp" android:paddingTop="8dp"
        android:paddingRight="4dp" android:paddingBottom="8dp"
        android:textStyle="bold" android:singleLine="true" android:ellipsize="end"/>
    <TextView android:id="@+id/count" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="count"
        android:layout_gravity="center_horizontal"
        android:paddingLeft="4dp" android:paddingTop="8dp"
        android:paddingRight="4dp" android:paddingBottom="8dp"
        android:textStyle="bold" android:singleLine="true" android:layout_weight="1" />
</LinearLayout>

William


set android:layout_weight="1" for the first textview and not the second one. Also set layout_width="0" for the first textview instead of wrap_content

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜