崩溃 关于Android 滚屏控件:ScrollView 使用的一些细节和注意事项 - @drawable/item2"
说明:
ScrollView是一个顶层布局,可以实现大于手机屏幕的布局,从而实现布局中的内容超过一屏显示不下时可自动为页面提供上下滑动浏览功能。
常用参数:
滚动条不显示:android:scrollbars="none"滚动条恒显示:android:fadeScrollbars="false"设置水平滚动条的drawable(如颜色):android:scrollbarThumbHorizontal设置垂直滚动条的drawable(如颜色):android:scrollbarThumbVertical设置水平滚动条背景(轨迹)的色drawable(如颜色):android:scrollbarTrackHorizontal设定滚动条宽度:android:scrollbarSize
示例代码:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content" 拼多多帮助力入口
android:src="@drawable/item1"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/item2"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/item3"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/item4"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/item5"
/>
注意事项:
1,ScrollView控件是顶层控件尽量放在layout的最外层使用。
2,ScrollView控件只支持垂直滚动,如果要横向滚动请使用:HorizontalScrollView
3,ScrollView中只能包含一个控件,当超过一个时app运行时会崩溃,切记!
4,如果ScrollView并非最外层的控件,请在ScrollView内部再使用一个LinearLayout把这N个组件归在一起。务必!
常规使用方法:
通常是在〈ScrollView〉标签中定义一个容器标签并且在标签中将android:orientation属性值设置为 vertical,然后在标签中的控件所占用的总高度超出屏幕的高度,就会 在屏幕的右侧出现一个滚动条。
精彩链接