Android: Something better than android:ellipsize=“end” to add “…” to truncated long Strings?

做~自己de王妃 提交于 2019-11-27 11:39:33

If it's for a single line try this:

android:ellipsize="end"
android:maxLines="1"
android:scrollHorizontally="true"
android:singleLine="true"

It worked for me.

I had a similar problem and setting this property to the TextView helped:

android:singleLine="true"

Also, I was using a RelativeLayout so I limited the space the TextView could take by setting a left margin to a button to the right of the TextView, so that the text cannot expand further and is forced to truncate its content.

Maybe it's not the solution to your problem, but it helped me in a similar situation.

See my update 3. The workaround was using " marquee". I have seen many apps doing that at this time. Now, with new versions of Android this feature is most likely fixed and will work as expected. (my guess)

Maybe you could take a look at how the private Ellipsizer class used by the OS works and modify it for your app?

Edit: Here's a working link - http://androidxref.com/5.1.0_r1/xref/frameworks/base/core/java/android/text/Layout.java#1830

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!