Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TextView with scrollbars and maxHeight

Tags:

I need to set the TextView maximum height (either using maxHeight or maxLines). And if there are more lines of text the scrollbars should be shown. What markup should I use for this?

Initial idea was to wrap TextView with ScrollView, but ScrollView has no maxHeight attribute.

like image 588
alex2k8 Avatar asked Mar 19 '10 15:03

alex2k8


1 Answers

Layout:

<TextView     android:id="@+id/text_view"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:singleLine="false"     android:maxLines="3"     android:scrollbars="vertical"     android:textColor="@android:color/secondary_text_dark_nodisable"     > </TextView> 

Code:

TextView textView = (TextView)findViewById(R.id.text_view); textView.setMovementMethod(ScrollingMovementMethod.getInstance()); 

Note:

The android:textColor="@android:color/secondary_text_dark_nodisable" is used to avoid text fade out when textView is touched.

like image 129
alex2k8 Avatar answered Oct 10 '22 14:10

alex2k8