1

In Android, how could I limit the width of the TextView by putting three dots at the end of the text if the length is greater to certain limit ?

gunar
  • 14,660
  • 7
  • 56
  • 87
Anshu P
  • 63
  • 4
  • 14

2 Answers2

10

put this code to your TextView

android:ellipsize="end"
android:singleLine="true"   // if you want 3 dots for single line, add this.
android:maxLines="2" // if you want 3 dots after two lines, add this.
canova
  • 3,965
  • 2
  • 22
  • 39
1

Use the ellipsize property for this purpose.

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/text_mytext"
    android:ellipsize="end"
    android:singleLine="true"
    />

The code similar to the above should work for you. Also set maxLines=1.

Idrizi.A
  • 9,819
  • 11
  • 47
  • 88
Dash
  • 314
  • 2
  • 14