这是一个滚动视图,就是说若是你在你的UI中容不下那么多的内容,且你对本身的UI都已经设置好了px,OK,那么在适应屏幕过程当中,咱们并不但愿使之压缩,因而咱们能够采用ScrollView这个空间来包裹!html
注意,值得一提的是,它只能包裹一个组件,所以,你必须在这个过程当中只能使用一个Layout来布局哦!android
固然上面所说的是,是垂直方向上的布局,若是是要采用水平布局的话,那么你能够采用HorizontalScrollView!布局
ScrollView,经过官方文档的继承关系能够看出,它继承自FrameLayout,因此它是一种特殊类型的FrameLayout,由于它可使用用户滚动显示一个占据的空间大于物理显示的视图列表。值得注意的是,ScrollView只能包含一个子视图或视图组,在实际项目中,一般包含的是一个垂直的LinearLayout。学习
值得注意的是,ScrollView不能和ListView一块儿使用,由于ListView已经对垂直方向的滚动作了处理,它会迫使若是ListView的内容大于物理视图的内容的时候,强制垂直滚动的效果,因此这里使用ScrollView和ListView混合使用是没有意义的,对于ListView的讲解,能够参见个人另一篇博客:Android--UI之ListView。ScrollView还须要注意EditText自带的多行输入的滚动效果,也是不能够混合使用的,若是在ScrollView中包含了多行的EditText,那EditText中自带的滚动效果将失效。其中心思想就是ScrollView是一个滚动视图的容器,对于一些自带了滚动效果的控件,是没法和它一块儿被混合使用的。code
在Android平台下,与ScrollView相似的还有一个HorizontalScrollView容器,这个容器与ScrollView的做用相反,主要适用于水平滚动,了解了ScrollView就基本上了解了HorizontalScrollView,因此这里着重讲解ScrollView的使用。xml
ScrollView其实就是一个布局,因此基本上没有什么太多的本身的方法或者属性须要特别讲解。这里直接展现一个Demo来说解一下使用以及效果便可,这里提供了十张图片,须要放置在res/drawable-hdpi目录下。htm
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="垂直滚动视图" android:textSize="30dp" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp1" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp2" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp3" /> <EditText android:maxLines="2" android:layout_width="match_parent" android:layout_height="40dp" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp4" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp5" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp6" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp7" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp8" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp9" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/bmp10" /> </LinearLayout>
效果图:blog
对于HorizontalScrollView而言,其实全部的思想都与ScrollView相似,惟一的区别是HorizontalScrollView是支持水平滚动的。在上面的实例中,只须要改变一下外围的ScrollView为HorizontalScrollView,再把其中包裹的LinearLayout的android:orientation属性设置为horizontal便可实现水平滚动的效果。继承
以上是借用了园友的博客,由于这个实在是不必详细地进行介绍,在此很是感谢那位园友的分享,在这里,特地贴出以上资源的来源-------Android--UI之ScrollView图片
若是有人非说我无耻拿园友的博客转载的话,在此表示深深的歉意,我认可转载了!但我仍然会遵循本身的写文原则:分享本身想分享的,写本身想写的,引用必写明原处,不辜负任何一位愿意出来分享的人,让你们都能和平地学习与工做!