ScrollView属性fillViewport解决android布局不能撑满全屏的问题
2016-05-05 21:43
459 查看
http://www.2cto.com/kf/201208/148262.html
ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
在ScrollView中添加一个Android:fillViewport="true"属性就可以了。顾名思义,这个属性允许 ScrollView中的组件去充满它。 当ScrollView没有fillVeewport=“true”时,
里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.
例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度。
布局文件。
<?xml version="1.0" encoding="utf-8"?>
<!-- 背景:蓝色 -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff" >
<!-- 背景:绿色 -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Hello Android." >
</TextView>
</LinearLayout>
</ScrollView>
效果图。
尽管已经设置了android:layout_height="fill_parent",但是,整个LinearLayout和TextView还是不能充满整个屏幕。
解决办法。
在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。
修改后的效果图。
ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
在ScrollView中添加一个Android:fillViewport="true"属性就可以了。顾名思义,这个属性允许 ScrollView中的组件去充满它。 当ScrollView没有fillVeewport=“true”时,
里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了"fill_parent"),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.
例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度。
布局文件。
<?xml version="1.0" encoding="utf-8"?>
<!-- 背景:蓝色 -->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff" >
<!-- 背景:绿色 -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00ff00" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Hello Android." >
</TextView>
</LinearLayout>
</ScrollView>
效果图。
尽管已经设置了android:layout_height="fill_parent",但是,整个LinearLayout和TextView还是不能充满整个屏幕。
解决办法。
在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。
修改后的效果图。
相关文章推荐
- 第11章 Android的线程和线程池
- Android Q&A | setOnItemClickListener(AdapterView.OnItemClickListener) in the type AdapterView....
- 学习android笔记(3):自定义动画
- 学习android笔记(1):隐藏系统自定义titleBar
- 移动开发生态渐成
- Android ----SQLiteDate(Cursor接口)
- 阿里无线的雄心壮志
- Android项目构成之AndroidManifest.xml文件简介
- android之ListView分页加载数据
- 服务android
- 去除android控件滑动的时候出现的阴影
- Android Studio快捷键
- 解决android中listview中嵌套checkbox滑动时checkbox状态改变问题
- android studio 包依赖
- Android打开输入法和关闭输入法
- android studio 多渠道打包
- Android Fragment 真正的完全解析(上)
- android:全屏设置 + 去标题 + 只去程序标题栏 (应用和activity设置)
- android studio 签名
- Android内存泄露分析和处理