1、单独的TextView控件设置滚动条
<TextView
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="file content is empty!"
android:scrollbars="vertical"
android:fadeScrollbars="false"/>
mFileContentView.setMovementMethod(ScrollingMovementMethod.getInstance());
经过上面两个步骤,TextView就可以上下滚动了,如果想自定义滚动条,接着在xml里面加入属性:
android:scrollbarThumbVertical="@drawable/ic_launcher" //滑块的图片
android:scrollbarTrackVertical="@drawable/ic_launcher" //滑道的图片
ScrollBar由两部分组成,一个是Track(滑道),一个是Thumb(滑块)
2、也可以用ScrollView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fadingEdge="vertical">
<TextView
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="file content is empty!"/>
</ScrollView>
本文详细介绍了在Android应用中通过设置TextView的scrollbars属性和使用ScrollView来实现文本内容的上下滚动显示的方法。同时,还展示了如何自定义滚动条样式,包括滑块和滑道的图片。通过这两个步骤,可以有效地处理长文本内容的显示问题,提升用户体验。
671





