Android 技术总结(004)—— ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
2015-09-09 14:36
721 查看
例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度。
布局文件。
[html]
<?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中的组件去充满它。
修改后的效果图。
作者:manoel
from:http://www.2cto.com/kf/201208/148262.html
布局文件。
[html]
<?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中的组件去充满它。
修改后的效果图。
作者:manoel
from:http://www.2cto.com/kf/201208/148262.html
相关文章推荐
- Android的onLayout、layout方法讲解
- android坐标
- Android第四十七期 - WheelView沉浸式菜单栏
- Android第四十七期 - WheelView沉浸式菜单栏
- Qt for android 界面适应
- 修改nexus 7的boot.img,打开系统调试
- Caused by: android.os.NetworkOnMainThreadException错误解决办法
- Android依赖注入应用
- Android应用程序用户界面(九)- 按钮
- android 群组头像的显示(仿QQ群组)
- Android获取当前连接wifi的信道
- Ionic Android开发环境搭建 上
- Android笔记(二十七)数据持久化技术
- 剖析Android中进程与线程调度之nice
- KenBurnsView:实现Ken Burns effect图片展示效果的效果android控件
- Android apk文件资源混淆原理及实现
- Android简单有效Viewpager+Fragment实现滑动标签页
- android实现的计算器功能,可以加减乘除;可以倒退,可以清空文本,大家参考使用吧
- Android SQLite 显式事务控制优化插入数据
- Android笔记(二十四) Android中的SeekBar(拖动条)