0

I want to display part of a long text string in a single line TextView without breaking words or ellipsizing.

For example,

This is my very long text string, which is extremely long.

I want this to show up in a single-line TextView as

This is my very long text

NOT

This is my very long text strin

OR

This is my very long text st...

Matt Robertson
  • 2,928
  • 5
  • 34
  • 62

1 Answers1

0

You can use a StringTokenizer with a space separation to iterate throw your words. Use this code to check the current string could fit in the TextView:

Rect bounds = new Rect(); 
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text, 0, text.length(), bounds);
int textWidth = bounds.getWidth();
Gabor Novak
  • 286
  • 1
  • 7