I really cannot figure out why, but I am only able to get ellipsize working on maxLines=2
and more. I am displaying a few words of description and then a long string with no spaces.
This is how the TextView looks like:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#757575"
android:text="@string/gcm_not_registered"
android:maxLines="1"
android:ellipsize="end"
android:id="@+id/login_gcmRegistrationTextView"/>
I then programatically set a text to it, but depending on the maxLines limitation, I get two different results:
The only thing that changed was the maxLines
, why isn't the line filled in the first picture as well?
There are two ways to fix it:
android:ellipsize="end"
attribute to android:ellipsize="marquee"
.android:maxLines="1" android:ellipsize="end"
attributes and add android:singleLine="true"
attribute.This code works for me:
In the xml add:
ellipsize
: marquee
lines
: 1
In java:
<yourTextView>.setHorizontallyScrolling(true);
<yourTextView>.setSelected(true);
If there is another item that request the "focus" you lose the marquee effect. The textView
need the state selected to prevent this.
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