Limit numbers of lines in TextView

后端 未结 7 1267
忘掉有多难
忘掉有多难 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 01:59

    I tried as said in accepted answer and others but didn't worked for me, but after adding android:ellipsize="marquee" it's working now..

    0 讨论(0)
  • 2021-02-01 02:07
    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="120dip" >
    
    <TextView
        android:id="@+id/tv_addesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:maxLines="12"
        android:scrollbars="vertical"
        android:textColor="#FFFFFFFF"
        android:textSize="15sp" />
     </ScrollView>
    
    0 讨论(0)
  • 2021-02-01 02:12

    Try using this.

    android:maxLines="12"
    android:ellipsize="end"
    

    In the end it add ... if extra text available.

    You can also use

    android:ellipsize="marquee" 
    

    It will reduce extra text from end that is not like a word.

    0 讨论(0)
  • 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())
    
    0 讨论(0)
  • 2021-02-01 02:16

    Find your textview by id:

    TextView myTextBox=(TextView)findViewById(R.id.textBox);
    

    Now use the setMaxLines function and assign the number of lines you require in it,say 20.

    myTextBox.setMaxLines(20);
    

    This limits your text box to show 20 lines only.

    0 讨论(0)
  • 2021-02-01 02:18

    hey try setting the singleline property to false. Just see if it works.

    0 讨论(0)
提交回复
热议问题