Textview滚动无法正常工作

时间:2012-12-02 19:45:48

标签: android xml layout scroll textview

我想垂直向下和向上滚动文本,使文本中出现的文本比空格更长。 但是,我测试的以下方法不起作用。

1 - tv1.setMovementMethod(new ScrollingMovementMethod()); 此外,使用此方法时,对onFling()方法的调用将停止工作。

2 - 在布局XML中使用<ScrollView>。 此外,使用此方法时,调用onFling()方法停止工作。

<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>

布局XML中的TextView如下所示。

<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" />

3 个答案:

答案 0 :(得分:10)

View内的TextViewListView不能滚动ScrollView。 因此,在普通布局中使用简单的TextView并向其添加android:scrollbars属性。

<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" />

Activity方面,您必须写下以下内容:

tv1.setMovementMethod(new ScrollingMovementMethod());

(基本上与你在第一点描述的相同)

答案 1 :(得分:3)

你可以尝试:

<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>

答案 2 :(得分:1)

<ScrollView
android:id="@+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <TextView
    android:id="@+id/TEXT_STATUS_ID"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

</ScrollView>
相关问题