android ScrollView fillViewport属性
来源:互联网 发布:sql语句大全实例教程 编辑:程序博客网 时间:2024/05/18 01:21
为了屏幕适配,包含多元素的布局一般都会使用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 ScrollView
if needed. When the child is taller than the ScrollView
, the attribute has no effect.
添加属性后的效果图:
- android ScrollView fillViewport属性
- scrollView属性fillviewport
- ScrollView属性fillViewport解决android布局有空白问题
- 关于ScrollView的fillViewport属性
- Android fillViewPort属性用法
- scrollView fillviewport
- Android 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
- Crypto++库在VS 2013中的使用 + 基于操作模式AES加密
- Dijkstra's shortest path algorithm
- nyoj746整数划分(四)【区间dp】
- JDK1.7的新特性
- 毕业十年记
- android ScrollView fillViewport属性
- codeforces 567C Geometric Progression (map维护)
- Android aidl Binder框架浅析
- php能把函数名作为参数传递吗?
- Java之正则表达式验证手机号码
- 反转一个单向链表
- redis功能丰富
- 当心从10亿估值沦落到一无所获!创业者签订融资协议时该注意什么?
- JSON解析