使用 ScrollView 实现滚动效果
14 Jul
ScrollView 也是一个 Layout 布局,可以让它内部的数据显示不下的时候出现滚
动条,要注意的是不能在 ScrollView 中放 多个组件,如果放了多个组件,会出
现如下错误:ERROR/AndroidRuntime(271): Caused by:
java.lang.IllegalStateException: ScrollView can host only one direct
child (ScrollView 只能包裹一个直接子元素)
我们看一个例子:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/andr
oid">
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0"
xmlns:android="http://schemas.android.com/apk/res/android">
<TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView android:text="色彩透明度测试"
android:textSize="18dip"
android:layout_span="2"
android:layout_gravity="center"
android:layout_width="fill_par
ent" android:layout_height="fill_parent">
</TextView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="30dip">
<TextView
android:background="#ff00ff00"
android:layout_width="fill_par
ent" android:layout_height="fill_parent">
</TextView>