I have set up a text view as follows:
<TextView
android:id="@+id/TextView_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:ellipsize="end"
android:maxLines="3"
android:textColor="@color/white"
android:textIsSelectable="false"
android:textSize="14sp" />
The text inside is set programatically by a layout inflator, with the text coming from an XML feed. I've checked the source and there are no stray characters or line breaks.
Testing this TextView on a Nexus 4 running Android 4.3 I'm seeing weird behaviour.
The string inside ends: ""Lorem ipsum dolor sit amet"
On the Nexus this is truncating at the right place, but instead of ending with the ellipsis character like: "dol...", I'm getting "dol...s" with the final character half obscured as it breaks through the margin.
Increasing the margin then gives me "ipsum...dol" at the end.
I've checked this on my other test Devices a Galaxy S3 running 4.1.2 and a Desire C running 4.0.3 and it isn't present on those.
Has anybody else seen this behaviour with ellipsize:end? Any suggestions for what I might have done wrong or how I can get around this?
Through a lot of trial and error, I just found that it is caused by having a '\n' character. There is some sort of problem with ellipsize="end" when there is a new line somewhere in the text, even if it is well after the ellipsize.
doing simply:
text = text.replace('\n',' ');
fixed this problem for me
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