Reputation: 32233
I want to limit the amount of space a TextView can take in the screen with the following rules:
Here go some screenshots explaining valid and invalid results:
Short Text:
Medium Text:
Internal Scroll:
Blank spaces:
Excessive length:
Upvotes: 5
Views: 7072
Reputation: 633
It's easy if you want to limit TextView's height by line, use android:maxLines
:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical"
android:requiresFadingEdge="vertical" />
In your code, write as below:
yourTextView.setMovementMethod(new ScrollingMovementMethod());
With this code, your TextView can be scrolled vertically when the text is longer than the maxLines.
Upvotes: 3
Reputation: 6162
Try like this.
XML
<TextView
android:id="@+id/descTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical"
android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."
android:textColor="#232e3b"
android:typeface="sans" />
in JAVA
descTxtView= (TextView) findViewById(R.id.descTxtView);
descTxtView.setMovementMethod(new ScrollingMovementMethod());
Upvotes: 9