ScrollView就是一个可以滚动的View,这个滚动的方向是垂直方向的,而HorizontalScrollView则是一个水平方向的可以滚动的View。二者用法一样,这里就以ScrollView为例写一个小小的例子。
首先看一下main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/main_content"/>
</ScrollView>
</LinearLayout>
这里的include引入的是内容,也可以是一个非常复杂的布局文件。放在ScrollView里面后,就变成可上下滑动了。
main_content.xml里面是一段用来显示效果的长段文字。这里就不贴出来了。
然后看一下效果图:
这就是简单又实用的滚动控件ScrollView。。。