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:Layout_weight属性解析
  2. android edittext的属性
  3. Android 官方架构组件之 Lifecycle的学习
  4. android:onClick 属性的应用
  5. android的Http请求组件
  6. Android组件通信
  7. android:imeOptions属性详解(Enter功能)

随机推荐

  1. Android(安卓)NFS 文件系统
  2. Android消息机制(三):Looper
  3. Android实现搜索保存历史记录功能
  4. Android(安卓)Camera2.0 结合ImageReader
  5. Android(安卓)SDK更新后提示This version
  6. 【Android】【UI】8.0以上版本Notificati
  7. Android中常用的设计模式(一)
  8. Android(安卓)4.4 Kitkat Phone工作流程
  9. 关于Android(安卓)国际化遇到的一些坑
  10. Android(安卓)Interpolators