Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView Ellipsize (...) not working

I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don't know why - but I don't get it.

I already wrapped my head around similar StackOverflow questions, but I ended up with no solution. Maybe someone has some useful hints.

<LinearLayout      android:layout_height="wrap_content"      android:layout_width="fill_parent"     android:orientation="vertical">      <TextView          android:textStyle="bold"          android:text="Full Name"          android:layout_height="wrap_content"          android:textSize="16sp"         android:layout_width="wrap_content"          android:id="@+id/lName"         android:layout_gravity="center_vertical"          android:maxLines="1"         android:ellipsize="end"/> </LinearLayout> 

The LinearLayout above is nested into 2 other LinearLayouts. Maybe this is important to know. I already tried the attribute "singleLine" too, but some say this is deprecated and it doesnt work anyway.

like image 973
Bins Ich Avatar asked Jun 29 '12 12:06

Bins Ich


People also ask

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.

What is Ellipsize marquee?

If you want a horizontal scrollable text in your app, use android:ellipsize="marquee" where a single line large text will be scrolling.

What is android EMS?

android:ems is the number of 'M' occurrences in a EditText field. it points to its width.

How do I make TextView disappear?

you should use this: myText. setVisibility(View. INVISIBLE);


2 Answers

Add the following styles in your styles file (typically styles.xml):

<style name="autoscroll">     <item name="android:singleLine">true</item>     <item name="android:ellipsize">marquee</item>     <item name="android:marqueeRepeatLimit">marquee_forever</item>     <item name="android:focusable">true</item>     <item name="android:focusableInTouchMode">true</item>     <item name="android:scrollHorizontally">true</item> </style> 

Then add the style @style/autoscroll to your TextView:

<TextView android:id="@+id/lName"       style="@style/autoscroll" /> 

You can reuse your autoscroll feature easily when you want this way.

like image 150
Stefano Ortisi Avatar answered Sep 18 '22 08:09

Stefano Ortisi


Add this in your xml for the TextView:

        android:maxWidth="200dp"          android:maxLines="1"  

As

        android:singleLine="true"   

is deprecated.

like image 44
Khan Avatar answered Sep 18 '22 08:09

Khan