关于Android 滚屏控件:ScrollView 使用的一些细节和注意事项

生活中,最使人疲惫的往往不是道路的遥远,而是心中的郁闷;最使人痛苦的往往不是生活的不幸,而是希望的破灭;最使人颓废的往往不是前途的坎坷,而是自信的丧失;最使人绝望的往往不是挫折的打击,而是心灵的死亡。所以我们要有自己的梦想,让梦想的星光指引着我们走出落漠,走出惆怅,带着我们走进自己的理想。

导读:本篇文章讲解 关于Android 滚屏控件:ScrollView 使用的一些细节和注意事项,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

关于Android 滚屏控件:ScrollView 使用的一些细节和注意事项

说明:

ScrollView是一个顶层布局,可以实现大于手机屏幕的布局,从而实现布局中的内容超过一屏显示不下时可自动为页面提供上下滑动浏览功能。

常用参数:

  • 滚动条不显示:android:scrollbars=”none”
  • 滚动条恒显示:android:fadeScrollbars=”false”
  • 设置水平滚动条的drawable(如颜色):android:scrollbarThumbHorizontal
  • 设置垂直滚动条的drawable(如颜色):android:scrollbarThumbVertical
  • 设置水平滚动条背景(轨迹)的色drawable(如颜色):android:scrollbarTrackHorizontal
  • 设定滚动条宽度:android:scrollbarSize

示例代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:scrollbars="none"
 >
 <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="@drawable/item1"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item2"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item3"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item4"
   />
  <ImageView
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:src="@drawable/item5"
   />
 </LinearLayout>
 
</ScrollView>

注意事项:

1,ScrollView控件是顶层控件尽量放在layout的最外层使用。

2,ScrollView控件只支持垂直滚动,如果要横向滚动请使用:HorizontalScrollView

3,ScrollView中只能包含一个控件,当超过一个时app运行时会崩溃,切记!

4,如果ScrollView并非最外层的控件,请在ScrollView内部再使用一个LinearLayout把这N个组件归在一起。务必!

常规使用方法:

     通常是在〈ScrollView〉标签中定义一个<LinearLayout> 容器标签并且在<LinearLayout>标签中将android:orientation属性值设置为 vertical,然后在<LinearLayout〉标签中放置多个控件,如果 <LinearLayout>标签中的控件所占用的总高度超出屏幕的高度,就会 在屏幕的右侧出现一个滚动条。 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/139905.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!