Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView: Get it to truncate without respect to spaces between words

How do you configure a TextView to truncate in the middle of a word?

So if I have text="Some Text" I want it to show as "Some Te" assuming the width supports that.

What instead I'm seeing is "Some"; its truncating the entire word "Text" even though there is plenty of space for a couple more characters.

like image 476
Fraggle Avatar asked Jul 06 '11 18:07

Fraggle


2 Answers

Here is what worked for me:

<TextView 
    android:layout_width="80px"
    android:layout_height="wrap_content"
    android:text="Some text"
    android:background="#88ff0000"
    android:singleLine="true"
    android:ellipsize="marquee"/>

enter image description here


Or with "..." at the end:

<TextView 
    android:layout_width="80px"
    android:layout_height="wrap_content"
    android:text="Some text"
    android:background="#88ff0000"
    android:singleLine="true"
    />

enter image description here


While using android:lines doesn't work:

<TextView 
    android:layout_width="80px"
    android:layout_height="wrap_content"
    android:text="Some text"
    android:background="#88ff0000"
    android:lines="1"
    android:ellipsize="marquee"/>

enter image description here

This is most likely a bug and I believe I've seen some bug report about that.

like image 106
inazaruk Avatar answered Nov 13 '22 11:11

inazaruk


Here is my code for a TextView that "truncates" the word with no ellipsis. It doesn't quite cut it off, it simply lets it run off the edge, giving the slight impression that it's been truncated.

<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:singleLine="true"
    android:scrollHorizontally="false"
    android:ellipsize="none"
    android:text="@string/hello"
/>
like image 28
Otra Avatar answered Nov 13 '22 11:11

Otra