android ScrollView fillViewport属性
2015-08-06 20:06
447 查看
为了屏幕适配,包含多元素的布局一般都会使用
我们希望最后的Button是置底的,同时是可以跟随滑动的
例如定义布局xml如下:
运行效果是这个样子:
原因就是当子布局高度小于ScrollView的高度时,定义子布局match_parent或者fill_parent不起作用,因此设置layout_gravity也不起作用
在scrollview里添加属性android:fillViewport=”true” 就可以了,使得子布局高度和scrollview一样,而当子布局高度超过scrollview的高度时,这个属性就没有意义了
Romain Guy write
a little info about a ScrollView attribute
that is missing from documentation :android:fillViewport=”true” .
It must be set to ScrollView and has the following efect : when set to true, this attribute causes the scroll view’s child to expand to the height of the
needed. When the child is taller than the
添加属性后的效果图:
ScrollView,以便小屏手机滑动查看,但是在大屏手机上内容全部加载,导致下方空白
我们希望最后的Button是置底的,同时是可以跟随滑动的
例如定义布局xml如下:
<span style="font-family:Verdana, Geneva, Arial, Helvetica, sans-serif;"><?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" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_height="350dp" android:layout_width="match_parent" android:orientation="vertical" android:background="#ffffff00"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="content"/> </LinearLayout> <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="horizontal"> <Button android:layout_width="match_parent" android:layout_height="45dp" android:layout_gravity="bottom"/> </LinearLayout> </LinearLayout> </ScrollView></span>
运行效果是这个样子:
原因就是当子布局高度小于ScrollView的高度时,定义子布局match_parent或者fill_parent不起作用,因此设置layout_gravity也不起作用
在scrollview里添加属性android:fillViewport=”true” 就可以了,使得子布局高度和scrollview一样,而当子布局高度超过scrollview的高度时,这个属性就没有意义了
Romain Guy write
a little info about a ScrollView attribute
that is missing from documentation :android:fillViewport=”true” .
It must be set to ScrollView and has the following efect : when set to true, this attribute causes the scroll view’s child to expand to the height of the
ScrollViewif
needed. When the child is taller than the
ScrollView, the attribute has no effect.
添加属性后的效果图:
相关文章推荐
- Android Design Support Library使用示例(一)
- Android代码内存优化建议-Java官方篇
- Android代码内存优化建议-Android官方篇
- Android代码内存优化建议-Android资源篇
- android侧滑菜单框架SlidingMenu的使用
- Android 消息推送
- Android学习路线——渐进
- Android aidl Binder框架浅析
- Android 开源框架之AndroidAnnotations快速入门
- Android studio SDK下载相应版本的Android源码
- Android系统中设置TextView的行间距
- Android ORM数据库框架对比
- Android onconfiguration属性
- Android 圆形滚动菜单
- Android中的布局优化方法
- 仿Android L 长按Home键显示最近使用应用信息及清理
- Android布局优化
- android textview 超链接跳转到浏览器
- Android中 View not attached to window manager错误的解决办法
- android中使用LocationManager定位获取信息