*
ScrollView里只能包含一个子控件,多余一个就会报错*
需要放多个View的集合,所以用一个布局文件包裹。
ScrollView里的高度无效。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
/>
</LinearLayout>
</ScrollView>
此时虽然高度充满但是只有图片那么大
重点内容
**
如果要设置高度的大小 需要在LinearLayout里添加**
滚动条的属性
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none" //设置不显示滚动条
>
设置滚动条的样式。
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarTrackVertical="@drawable/scrollbar_bg" //滚动条滚动的背景样式
android:scrollbarThumbVertical="@drawable/scrollbar" //滚动块的样式
android:scrollbarSize="20dp"//滚动条大小
>
v4包下的ScrollView
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarTrackVertical="@drawable/scrollbar_bg"
android:scrollbarThumbVertical="@drawable/scrollbar"
android:scrollbarSize="20dp"
>