0

I want to clip extra text from text view. I want this type of look.

Hello! Asad you are a go...

instead of

Hello! Asad you are a good boy. Where do you live?

is that possible in android?

  • 1
    possible duplicate of [Add three dot to the end of dynamic text android](http://stackoverflow.com/questions/15615984/add-three-dot-to-the-end-of-dynamic-text-android) – Tony Nov 11 '13 at 23:15

2 Answers2

0

Using this

Rect bounds = new Rect();
Paint textPaint = textView.getPaint();
textPaint.getTextBounds(text,0,text.length(),bounds);
int height = bounds.height();
int width = bounds.width();

from this post. How to get string width on Android?

You can calculate then if the width (pixel width) of the text is less then the width of the text view, if so then use ... If not then display full message.

or this

<TextView
                    android:id="@+id/text_value"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:maxLines="1" />

From this post Clipping extra text which is getting out of bounds TEXT VIEW :: ANDROID

Community
  • 1
  • 1
Tony
  • 4,609
  • 2
  • 22
  • 32
0

add this attribute to your textview:

android:ellipsize="marquee"
superuser
  • 731
  • 10
  • 28