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

前端 未结 21 1851
野的像风
野的像风 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条回答
  •  不思量自难忘°
    2020-12-02 04:22

    code:

    TextView your_text_view = (TextView) findViewById(R.id.your_id_textview);
    your_text_view.setEllipsize(TextUtils.TruncateAt.END);
    

    xml:

    android:maxLines = "5"
    

    e.g.

    In Matthew 13, the disciples asked Jesus why He spoke to the crowds in parables. He answered, "It has been given to you to know the mysteries of the kingdom of heaven, but to them it has not been given.

    Output: In Matthew 13, the disciples asked Jesus why He spoke to the crowds in parables. He answered, "It has been given to you to know...

提交回复
热议问题