21

I have a View to that I need to add some text. The used View is:

<TextView 
  android:layout_marginLeft="10dp" 
  android:layout_width="wrap_content"
  android:gravity="center_vertical"
  android:layout_gravity="center" 
  android:maxLines="3"
  android:layout_height="70dp" 
  android:textColor="#000000"
  android:textSize="12dp" />

The problem i have is, if this text contains more than 3 line it just shows three line but no indication that it cut some line.
I want to append '...' at end of third line if it cut some data.

Janusz
  • 187,060
  • 113
  • 301
  • 369
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112

4 Answers4

51
<TextView android:layout_marginLeft="10dp" 
   android:layout_width="wrap_content" 
   android:gravity="center_vertical" 
   android:layout_gravity="center" 
   android:maxLines="3" 
   android:layout_height="70dp" 
   android:textColor="#000000" 
   android:textSize="12dp" 
   android:ellipsize="end"/> 

Use this code and it will work fine, the code android:ellipsize="end" will change this for you.

Samuel
  • 4,337
  • 3
  • 29
  • 35
  • 7
    This won't work. The documentation states: If set, causes words that are longer than the view is wide to be ellipsized instead of broken in the middle. In my test this causes a four line text view to stop displaying Text after the second line because at the end of the second line a word should be broken in the middle. Ellipsize won't put dots on the end of the textview after the third line. – Janusz Jan 04 '11 at 13:37
  • 3
    This will work with android:singleLine="true" , not with android:maxLines – matreshkin Jun 14 '13 at 07:24
  • Worked for me. no issues. – Safvan 7 Aug 01 '14 at 11:29
4
android:ellipsize="end"
fedj
  • 3,452
  • 1
  • 22
  • 21
1

It's not working if only we add android:ellipsize="end", we also need to add android:maxLines="3".

0
<TextView
 android:layout_marginLeft="10dp"
 android:layout_width="wrap_content"
 android:gravity="center_vertical"
 android:layout_gravity="center" 
 android:maxLines="3"
 android:layout_height="70dp" 
 android:textColor="#000000"
 android:textSize="12dp" 
 android:ellipsize="end"/>

add android:ellipsize="end"

Janusz
  • 187,060
  • 113
  • 301
  • 369
blindstuff
  • 18,298
  • 10
  • 47
  • 48
  • Thanks for that answer but still i have some problem and i posted on http://stackoverflow.com/questions/4021293/android-append-at-the-end-textview-edit – Labeeb Panampullan Oct 26 '10 at 10:56