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" />
Try:
android:singleLine="true"
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"
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.
My app started ignoring maxlines & ellipsize when I added
android:textIsSelectable="true"
It seems like these options are not compatible together.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With