Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ellipsize is not working

Tags:

android

layout

I have a TextView which i set the text using setText(). In properties, I have set:

Ellipsize = END
Lines = 1
Gravity = Left
Scroll Horizontal = False

But this clips extra text (clips text since where last space is found). But do not include dots ("...") at the end.

Example:

-------------------------------
|                             |
 Hi how are you ? And where are you now ?
|                             |
|                             |

After clipping:

-------------------------------
|                             |
 Hi how are you ? And where 
|                             |
|                             |

What I want:

-------------------------------
|                             |
 Hi how are you ? And where...
|                             |
|                             |

I am using Android 1.6. Plz help.

like image 383
Vpp Man Avatar asked Apr 02 '12 18:04

Vpp Man


3 Answers

android:singleLine="true" and textView.setEllipsize(TruncateAt.END);

These are the two key elements to achieve that.

like image 160
Arpit Garg Avatar answered Oct 17 '22 14:10

Arpit Garg


        android:singleLine

is deprecated.

Here is what the documentation says:

"This attribute is deprecated and is replaced by the textMultiLine flag in the inputType attribute. Use caution when altering existing layouts, as the default value of singeLine is false (multi-line mode), but if you specify any value for inputType, the default is single-line mode. (If both singleLine and inputType attributes are found, the inputType flags will override the value of singleLine.). [boolean]"

To solve your problem. You can use the following:

        android:ellipsize="end"
        android:maxLines="1"
like image 3
JaydeepW Avatar answered Oct 17 '22 15:10

JaydeepW


Textview has a property call singleLine make it true in your XML file.

If you are doing through code then

textView.setSingleLine(true);
like image 2
Shankar Agarwal Avatar answered Oct 17 '22 16:10

Shankar Agarwal