Reputation: 6922
I want to set TextView max line 2 and show "..." in the line middle.
My layout xml as below:
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="abcdefghijklmnopqrstuvwxyz"
android:ellipsize="middle"
android:maxLines="2"
android:textAppearance="?android:attr/textAppearanceLarge" />
But it show as below:
abcdefgh
ijklmnop
It show 2 lines, but it doesn't show any "..." at middle or end.
How can I modify it?
Upvotes: 2
Views: 182
Reputation: 2731
Set the android:ellipsize property on the TextView as required (probably to 'end').
Upvotes: 1
Reputation: 23638
Try to set android:ellipsize="end"
.
<TextView android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="abcdefghijklmnopqrstuvwxyz" android:ellipsize="end" <-----change it to end android:maxLines="2" android:textAppearance="?android:attr/textAppearanceLarge" />
Upvotes: 1
Reputation: 40218
android:ellipsize
will work only when there's not enough space to display the whole text of the TextView
. In your case, you've set android:layout_width
to fill_parent
and the text is not long enough, so no ellipsize is being used. Change the android:layout_width
to some small amount of dip
and you'll see the difference. Hope this helps.
Upvotes: 2