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.

1
  • 2
    You got 3 correct answers, you should really mark one as accepted.
    – blindstuff
    Oct 25, 2010 at 18:26

4 Answers 4

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.

3
  • 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 4, 2011 at 13:37
  • 3
    This will work with android:singleLine="true" , not with android:maxLines
    – matreshkin
    Jun 14, 2013 at 7:24
  • Worked for me. no issues.
    – Safvan 7
    Aug 1, 2014 at 11:29
4
android:ellipsize="end"
1
  • 1
    add android:scrollHorizontally="true"
    – fedj
    Oct 26, 2010 at 15:41
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"

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.