Limit numbers of lines in TextView

<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>

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())

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.


put your text view with in scroll view and set fixed height of scroll view.

<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>

set properties as per your need