Android: Last line of textview cut off

后端 未结 20 1312
北荒
北荒 2020-11-28 02:46

I have a horizontal LinearLayout containing a TextView followed by a Spinner next to it. This LinearLayout is dynamically

20条回答
  •  迷失自我
    2020-11-28 03:14

    I had the same problem and found a handy solution. I get the number of lines of the TextView after rendering and set the height according to the number of lines. Here is the code.

    TextView textView = (TextView) layout.findViewById(R.id.textView);
    textView.setText(this.text);
    textView.post(new Runnable() {
        @Override
        public void run() {
            int linesCount = textView.getLineCount();
            textView.setLines(linesCount);
        }
    });
    

提交回复
热议问题