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

前端 未结 4 1232
予麋鹿
予麋鹿 2020-12-02 15:34

This property makes

\"short and very-long-word\"

to

\"short and\"

. But I want to

相关标签:
4条回答
  • 2020-12-02 15:51

    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.

    0 讨论(0)
  • 2020-12-02 15:53

    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

    0 讨论(0)
  • 2020-12-02 16:02

    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.

    0 讨论(0)
  • 2020-12-02 16:08

    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)

    0 讨论(0)
提交回复
热议问题