Android Tips: cut textview to see ‘…’ (ellipsis)

Android tips: cut textview and add ellipsis

Single line

Add android:ellipsize=”end” in the properties of the texview.

If you want your text on one line, add android:singleLine=”true”.

Example:

<TextView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="Text to cut because it is too long"
  android:ellipsize="end"
  android:singleLine="true"
/>

Multi lines

If your textview will be on 2 lines for example, add android:maxLines=”2″ in your textview properties.

Example:

<TextView
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="Text to cut because it is too long but I want it on 2 lines"
  android:ellipsize="end"
  android:maxLines="2"
/>

I hope it helps,

WakeUp Sun

Leave a Reply

Your email address will not be published. Required fields are marked *

*

captcha

Please enter the CAPTCHA text

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>