TextView: make it crop without respect for spaces between words

How to configure 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 width supports this.

Instead, I see "Some"; its truncation of the whole word "Text", although there is plenty of room for a few more characters.

+6
source share
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


When using android:lines does not 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 mistake, and I believe that I saw a bug report.

+11
source

Here is my code for a TextView that "cuts" a word without an ellipsis. He didn’t completely turn it off, it just allows him to escape from the edge, creating a slight impression that it was 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" /> 
+2
source

Source: https://habr.com/ru/post/892163/


All Articles