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"?> 
 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#0000ff" > 
 
     
 
            android:id="@+id/linearLayout1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="#00ff00" > 
 
                    android:id="@+id/textView1" 
            android:layout_width="wrap_content" 
            android:layout_height="fill_parent" 
            android:layout_weight="1" 
            android:text="Hello Android." > 
         
     
 
 

效果图。


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


解决办法。

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


修改后的效果图。

 

更多相关文章

  1. Android学习——基础组件
  2. Android(安卓)ImageView的scaleType属性与adjustViewBounds属性
  3. 动态修改Android参数信息的方法绕过改机检测
  4. 学习android网址
  5. Android应用程序全屏显示的方法
  6. Android音乐播放器简单示例
  7. Android自定义属性,format详解
  8. 有关Android中EditText的一些属性
  9. android jni介绍

随机推荐

  1. 我无法定义我的错误
  2. 节点js / Express替换LAMP
  3. 如何使用phpunit测试用例测试ajax调用?
  4. 在数据库中存储行数或动态获取
  5. 3-腿和2腿的auth有什么区别?
  6. 网站优化之PHPCMS如何开启伪静态
  7. 如何在php中的谷歌分析中显示搜索概述
  8. 如何为MySQL中包含记录的现有表创建唯一
  9. PHP 轻量级的PHP类检测移动设备(包括平板
  10. 从PHP登录请求获取空的AJAX响应