I want to scroll text down and up vertically, incase the text to appear in the textview is longer than the space. However, the below methods I tested, do not work.
1 - tv1.setMovementMethod(new ScrollingMovementMethod());
Moreover, upon using this method, calls to onFling()
method stop to work.
2 - using <ScrollView>
in layout XML.
also, when using this method, calls to onFling()
method stop to work.
<ScrollView
android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="@+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</ScrollView>
my TextView in layout XML is the following.
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2.26"
android:background="@drawable/green"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
You can't have a scrollable View
, like TextView
or ListView
, inside a ScrollView
.
So use your simple TextView
inside a normal layout and add android:scrollbars
property to it.
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:lines="3"
android:scrollbars="vertical"
android:scrollbarStyle="insideOverlay"
android:fadeScrollbars="true"
android:fadingEdge="vertical" />
In the Activity
side you must write something like:
tv1.setMovementMethod(new ScrollingMovementMethod());
(Basically the same thing o described at your first point)
you can try it as:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</LinearLayout>
</ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With