Android ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
2015-02-04 12:59
537 查看
例子,在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中的组件去充满它。
修改后的效果图
(转自: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中的组件去充满它。
修改后的效果图
(转自:http://www.2cto.com/kf/201208/148262.html)
相关文章推荐
- Android 技术总结(004)—— ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
- Android Scrollview 内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件 android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法 .
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android中关于scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android的scrollview视图内部的子视图中android:layout_height="fill_parent"无效的解决办法
- Android Scrollview 内部组件android:layout_height="match_parent"无效的解决办法
- android中scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- 解决scrollView中设置组件fill_parent不起作用
- Android学习笔记——解决设置了android:layout_alignParentBottom="true"的控件会被弹出的输入法顶上去的问题
- android ListView条目的子布局设置android:layout_height="match_parent"无效
- listView 中relativeLayout 布局的 android:layout_alignParentBottom="true" 无效的解决办法
- listView 中relativeLayout 布局的 android:layout_alignParentBottom="true" 无效的解决办法
- ScrollView里面嵌套子控件时设置 android:layout_width="match_parent"无效
- 当在写android的xml文件中出现Unexpected text found in layout file: """的解决办法