ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法

在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许 ScrollView中的组件去充满它。



例子,在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="HelloAndroid." >
</TextView>
</LinearLayout>

</ScrollView>

效果图。


尽管已经设置了android:layout_height="fill_parent",但是,整个LinearLayout和TextView还是不能充满整个屏幕。


解决办法。

在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。


修改后的效果图。

更多相关文章

  1. Android(安卓)中文 SDK —— ADT 14.0.0 (ADT14插件更新说明)
  2. Android:Layout_weight属性解析
  3. Android(安卓)Layout机制研究
  4. 详解 Android(安卓)的 Activity 组件
  5. declare-styleable中format详解
  6. android EditText 属性
  7. android edittext的属性
  8. Android布局属性全面剖析
  9. 完美解决隐藏Listview和RecyclerView去掉滚动条和滑动到边界阴影

随机推荐

  1. Android界面组件Activity解析
  2. android升级ADT22没有R文件
  3. Android(安卓)主题资源风格定制
  4. Android创建Menu菜单实例
  5. Android使用okHttp(get方式)登录
  6. Android开发相关工具等资源快速查找地址
  7. Android开发之旅:进程与线程
  8. HorizontalScrollView 水平动态生成TextV
  9. Android RecyclerView基本使用
  10. [置顶] 入门Android开发--总目录