Limit numbers of lines in TextView

后端 未结 7 1405
忘掉有多难
忘掉有多难 2021-02-01 01:14

I have a scrollable textView, and I want to limit the number of lines displayed, however xml properties are not working :



        
7条回答
  •  轮回少年
    2021-02-01 02:14

    You just have to set a number of lines in your TextView like this:

    android:maxLines = "10"
    

    and you must also add:

    android:minLines="1"
    

    The rest of this not necessary if you are not using scrolling

    and a property which says that this TextView should be scrollable vertically:

    android:scrollbars = "vertical"
    

    And in your Java-code:

    yourTextView.setMovementMethod(new ScrollingMovementMethod())
    

提交回复
热议问题