Text TextView Text Truncate Behavior

In iOS, text control has this behavior when the text does not fit on the screen, it will be truncated, and "..." will be automatically added.

Any way to get similar behavior from Android TextView?

+5
source share
1 answer

Of course, you also have this in Android.

The property is called "Ellipsize" and you have several options.

In XML:

android:ellipsize="start|marquee|end" 

Or through the code

 textView.setEllipsize(TruncateAt.START | TruncateAt.END | TruncateAt.MARQUEE); 

Values:

  • Start . Puts a "..." at the beginning of the text.
  • End : puts "..." at the end
  • Marquee : Does the scroll pane have

NOTES: Single Line

TextView should be a single line, so for this to work, also do this (or their equivalent XML properties maxLines and singleLine ):

 textView.setSingleLine(true); 

or

 textView.setMaxLines(1); 

Notes: Marquee Mode

For Marquee to work, TextView must have focus (the marquee will begin to move as soon as you click on the text image). You can also force the scroll of the selected area:

 textView.setFocusable(true); textView.requestFocus(); 
+14
source

Source: https://habr.com/ru/post/1204183/


All Articles