阅读量:97
要实现TextView的自动滚动,可以使用以下方法:
- 使用ScrollView包含TextView来实现文本内容的滚动。在布局文件中添加一个ScrollView,然后在ScrollView中添加一个TextView,设置TextView的文本内容即可实现滚动效果。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your long text content here"
android:scrollbars="vertical"
android:id="@+id/textView"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"/>
</ScrollView>
- 使用android:ellipsize="marquee"和android:singleLine="true"来实现TextView的文字滚动效果。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your long text content here"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:singleLine="true"
android:scrollHorizontally="true"/>
这样设置之后,TextView中的文字会自动滚动,但需要保证TextView是可聚焦的,否则滚动效果可能无法正常显示。