0

I use below layout.xml to show ellipsize:

<TextView
    android:id="@+id/my_tv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ellipsize="middle"
    android:singleLine="true" />

And it can show ellipsize in TextView success.
But the ellipsize style in some devices only show one ".".
Such as below picture between M and k:
enter image description here
And some devices can show "...".
Such as below picture between J and p:
enter image description here
I want to let all devices show as style 2.
How can I modify it?

brian
  • 6,802
  • 29
  • 83
  • 124

2 Answers2

1

I think if you use &#8230; which represents ellipsize, it should work.

So for your example, it would be...

ABCDEFGHIJ&#8230;PQRSTUVWXYZ

Give it a go.

neo108
  • 5,156
  • 3
  • 27
  • 41
  • You mean replace string to …? – brian Jun 05 '13 at 02:29
  • But if in different devices, there are may different width and can show string length are different. – brian Jun 05 '13 at 02:30
  • @brian, how you are setting the TextView with strings before and after? Also, have a look at [this question](http://stackoverflow.com/questions/3769105/android-something-better-than-androidellipsize-end-to-add-to-truncated)... – neo108 Jun 05 '13 at 02:48
  • I only setText("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");. – brian Jun 05 '13 at 02:51
  • Ok. I just tried your code by setting the text to `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz` and `...` shows up correctly. I also added `android:scrollHorizontally="true"` and it seemed to work. Try adding `android:scrollHorizontally="true"` and see if that makes a difference in the devices it does not work. – neo108 Jun 05 '13 at 03:00
  • I try add android:scrollHorizontally="true", it still the same. – brian Jun 05 '13 at 03:07
  • I think the ellipsize is work. But it only show ".", but not "...". Is it possible modify? – brian Jun 05 '13 at 03:08
  • No @brian, I've run out of ideas. From what I understand, the ellipsize does not change the text but only displays `...` where ever we need it so don't think we can modify it. The docs say `You will often also want to set scrollHorizontally or singleLine as well so that the text as a whole is also constrained to a single line instead of still allowed to be broken onto multiple lines.`. We have tried both `scrollHorizontally or singleLine`. Which device are you testing on? – neo108 Jun 05 '13 at 03:25
  • I test on device ASUS TF201. – brian Jun 05 '13 at 03:42
  • Have a look at [this bug logged](https://code.google.com/p/android/issues/detail?id=33868). It might be relating to this bug. – neo108 Jun 05 '13 at 03:53
0

Don't use android:singleLine="true".You can use android:maxLines="1" .It's awsome

qixiaobo
  • 1
  • 2