Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show 3 dots at the end of text in textview

I know this question is asked many times, i have gone through all the solutions but still the problem is same.

i want my text length to be of 50 characters. now it is coming in 2 lines.

Below is what i did:

 <TextView             android:id="@+id/notification_Message"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_below="@+id/notification_head"             android:layout_centerHorizontal="true"             android:layout_margin="10dp"             android:gravity="center"             android:ellipsize="end"             android:maxLength="50"             android:text=" Hello developer. please check this message for long length. max length to 50 characters. "                 android:textSize="20sp" /> 

The text here is just a sample text i have added. it is not showing 3 dots at end rather showing message upto 50 characters. i have tried max lines also, single line false also. but no positive result. I also don't want to handle this thing programmatically by adding three dots logically.

Please help

like image 428
Anchit Mittal Avatar asked Feb 17 '14 09:02

Anchit Mittal


People also ask

How do I add bullet points in TextView?

The two Button s at the bottom have android:text="◄" and "►" .

What is ems in TextView?

ems is a unit of measurement. The name em was originally a reference to the width of the capital M. It sets the width of a TextView/EditText to fit a text of n 'M' letters regardless of the actual text extension and text size. Eg : android:ems Makes the EditText be exactly this many ems wide.

What is Ellipsize in TextView?

Android Ellipsize Android TextView ellipsize property Causes words in the text that are longer than the view's width to be ellipsized ( means to shorten text using an ellipsis, i.e. three dots …) instead of broken in the middle to fit it inside the given view.


2 Answers

Make a preset width for your TextView and add these attributes (Shout-out to @T-D)

android:ellipsize="end" android:maxLines="1" 

The maxLines will make sure that your text wont be shown in two lines and the ellipsize will add the three dots in the end.

Old Answer

android:ellipsize="end" android:singleLine="true" 
like image 118
Ibrahim Yildirim Avatar answered Oct 23 '22 06:10

Ibrahim Yildirim


For one line text with a dot but now it's Deprecated so don't use singleLine anymore

Thanks to this post I found that how to show dot after the end of text if we have more one line, it works for me :)

android:ellipsize="end" android:maxLines="2" 

Post here this answer because all answer here are for single line not for multiline

like image 39
Lokesh Avatar answered Oct 23 '22 06:10

Lokesh