Android, How to limit width of TextView (and add three dots at the end of text)?

前端 未结 21 1861
野的像风
野的像风 2020-12-02 03:44

I have a TextView that I want to limit characters of it. Actually, I can do this but the thing that I\'m looking for is how to add three dots (...) at the end o

21条回答
  •  Happy的楠姐
    2020-12-02 04:26

    In order to work with the android:ellipsize attribute, you have to limit the layout width of the TextView, such that the text is out of bounds from view of TextView.

    So, android:layout_width attribute plays a key role here, set it accordingly.

    One example can be:

    
    

    Now, here if the text in android:text="This is a very long text to be displayed" goes out of view from TextView with a android:layout_width="120dp", android:ellipsize="end" will truncate the text and place ...(3 dots) after it. i.e. This is very long... will be displayed in the TextView.

提交回复
热议问题