简体   繁体   中英

TextView is not scrolling smoothly

I tried using scrollView with the textView but it is not working smoothly. In the code, the textView i want to scroll is "writeCodeTV"

activity_program.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="com.example.abhishek.canddatastructureprograms.ProgramActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tV1"
android:text="CODE"
android:textColor="@android:color/holo_blue_dark"
android:textStyle="bold"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"

>

<TextView
    android:padding="5dp"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:textColor="@android:color/black"
    android:scrollHorizontally="true"

    android:scrollbars="vertical|horizontal"
    android:id="@+id/writeCodeTV"
    android:text="CODE"
    />
</HorizontalScrollView>
</ScrollView>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tV2"
    android:text="OUTPUT"

    android:textColor="@android:color/holo_blue_dark"
    android:textStyle="bold"
    android:paddingBottom="10dp"
    android:paddingTop="10dp" />
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:scrollbars="horizontal|vertical"
    android:id="@+id/writeOutputTV"
    android:textColor="@android:color/black"
    android:text="CODE"
    />
</LinearLayout>

Also used setMovementMethod for the TextView

ProgramActivity.java

writeCodeTV.setMovementMethod(new ScrollingMovementMethod())

What am I possibly doing wrong?

I changed the layout a bit and it worked, I changed the parent from scrollView to HorizontalScrollVIew and it worked.

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tV1"
android:text="CODE"
android:textColor="@android:color/holo_blue_dark"
android:textStyle="bold"
android:paddingTop="10dp"
android:paddingBottom="10dp" />
<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    >


<TextView
    android:padding="5dp"
    android:layout_width="fill_parent"
    android:layout_height="300dp"
    android:textColor="@android:color/black"
    android:scrollHorizontally="true"

    android:scrollbars="vertical|horizontal"
    android:id="@+id/writeCodeTV"
    android:text="CODE"
    />

</ScrollView>
</HorizontalScrollView>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tV2"
    android:text="OUTPUT"

    android:textColor="@android:color/holo_blue_dark"
    android:textStyle="bold"
    android:paddingBottom="10dp"
    android:paddingTop="10dp" />
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp"
    android:scrollbars="horizontal|vertical"
    android:id="@+id/writeOutputTV"
    android:textColor="@android:color/black"
    android:text="CODE"
    />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM