Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textview scrolling not working

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" />
like image 966
Dan Jurgen Avatar asked Dec 02 '12 19:12

Dan Jurgen


2 Answers

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)

like image 60
yugidroid Avatar answered Oct 16 '22 03:10

yugidroid


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>
like image 40
ρяσѕρєя K Avatar answered Oct 16 '22 04:10

ρяσѕρєя K