Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text does not ellipsize

I have a TextView set to ellipsize but when I put the text in it doesn't do so. Any ideas?

<TextView 
    android:id="@+id/LegalsView" 
    android:ellipsize="end"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium" />
like image 757
digipen79 Avatar asked Jul 20 '11 21:07

digipen79


4 Answers

Try:

android:singleLine="true"
like image 113
Edwin Evans Avatar answered Oct 16 '22 05:10

Edwin Evans


android:layout_width="wrap_content"

will allow the TextView to expand as long as it needs to (including running off the screen). To make it ellipsize, you're going to have to set a width as citizen conn recommended, preferably with android:layout_width="fill_parent" instead of an absolute value.

Additional hints: You'll also want to set the maxLines of the TextView (probably to 1), and to get the actual ellipsis ("...") to appear, you'll probably also have to set

android:scrollHorizontally="true"
like image 45
Glendon Trullinger Avatar answered Oct 16 '22 05:10

Glendon Trullinger


You need to match the settings for android can correctly calculate the position of the object. Has several possible combinations, and depends on the rest of the layout is on the same line.

This is a combination that works:

android:layout_width="0dip" // dynamic width
android:layout_weight="1"   // less weight, other objects still "0"
android:ellipsize="end"     // ... into end of text (right)
android:singleLine="true"   // one line, deprecated, but necessary for some ambients
android:maxLines="1"        // one line, new mode

In summary, you indicate the weight, if you use dynamic layout, or just a fixed size, then indicates to only have one line and configures how "..." is displayed.

like image 40
Rodrigo T. Avatar answered Oct 16 '22 03:10

Rodrigo T.


My app started ignoring maxlines & ellipsize when I added

android:textIsSelectable="true"

It seems like these options are not compatible together.

like image 6
WigglyWorld Avatar answered Oct 16 '22 04:10

WigglyWorld