How can I show ellipses on my TextView if it is greater than the 1 line?

后端 未结 7 1311
终归单人心
终归单人心 2020-11-30 22:19

I have the following Layout which does not work:



        
7条回答
  •  半阙折子戏
    2020-11-30 22:36

    The way it worked for me on multiple devices / APIs was programmatically like this (where tv is your TextView):

        if (tv.getLineCount() > 1) {
            int lineEndIndex = tv.getLayout().getLineEnd(0);
            String text = tv.getText().subSequence(0, lineEndIndex - 3) + "\u2026";
            tv.setText(text);
        }
    

提交回复
热议问题