我想垂直向下和向上滚动文本,使文本中出现的文本比空格更长。 但是,我测试的以下方法不起作用。
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" />
答案 0 :(得分:10)
View
内的TextView
或ListView
不能滚动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>