ScrollView其实也是一个容器,其可以添加一个子控件,当添加超过一个子控件时会出错。
一个最简单的实例,Activity下面一个TextView用于显示信息,宽度等同父控件,高度根据内容自动变化,当高度超过父控件时,这时候就需要滚动了。
将TextView嵌套在一个ScrollView里面,在xml中配置如下:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/textbiew1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TestView0" />
<Button
android:text="Button0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
</LinearLayout>
</ScrollView>
这样就实现了TextView的滚动效果,这应该是最简单的方法。
ok,现在有一个新需求,我要原始大小显示一张照片,这个照片显然可能比Activity大,而且是横竖都大,那就是说横行纵向我都要滚动,显然上面只有一个ScrollView是无法实现的,这时候可以使用ScrollView嵌套一个ScrollView在嵌套ImgView,在xml中配置如下:
额,貌似不行。