In iOS text control has this behavior where if text doesn't fit on the screen it will get truncated and "..." gets automatically appended.
Any way to get similar behavior from Android TextView?
Of course you also have this in Android.
The property is named "Ellipsize" and you have several options.
In XML:
android:ellipsize="start|marquee|end"
Or via code
textView.setEllipsize(TruncateAt.START | TruncateAt.END | TruncateAt.MARQUEE);
The values mean:
NOTES: Single Line
TextView
should be single line, so to make it work, also do this (or their equivalent XML properties maxLines
and singleLine
):
textView.setSingleLine(true);
or
textView.setMaxLines(1);
Notes: Marquee Mode
For the Marquee to work, the TextView
has to have focus (the marquee will start moving once you press the textview). You can also force the marquee to automatically scroll by issuing:
textView.setFocusable(true);
textView.requestFocus();
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