本文转载于:http://blog.csdn.net/Candicelijx/article/details/51773840

解决办法:

在ViewPager外面嵌套ScrollView时导致ViewPager 中内容不显示,解决的办法是在ScrollView标签下加入:android:fillViewport="true" ,顾明思义,这个属性ScrollView 中的组件去充满它。

原因分析:

ScrollView 里只放一个元素.

当ScrollView 里的元素想填满ScrollView时,使用android:fillViewport="true".

当ScrollView没有fillVeewport=“true”时, 里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了”fill_parent”),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.

本质:ScrollView中不能使用如下属性设置空间的高度

android:layout_width="match_parent"  android:layout_height="0dp"  android:layout_weight="1">  

例如,在ScrollView下加入如下组件,无论如何也不能自动扩展到屏幕高度。

<?xml version="1.0" encoding="utf-8"?>      <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"       android:id="@+id/scrollView1"       android:layout_width="match_parent"       android:layout_height="match_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=”match_parent”,但是,整个LinearLayout和TextView还是不能充满整个屏幕。解决办法。在ScrollView中添加一个android:fillViewport=”true”属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。

参考:http://www.2cto.com/kf/201208/148262.html

更多相关文章

  1. Android开发系列(二十二):AdapterViewFlipper的功能和使用方法
  2. 安卓程序代写 网上程序代写[原]ViewGroup(容器组件)详解(API解析
  3. EditText设置可以编辑和不可编辑状态
  4. 控制drawable资源大小
  5. Android使用shape设置虚线、圆角、渐变
  6. Android(安卓)兼容性测试(CTS)
  7. android TabHost 转
  8. Appium的代码实例及日志分析
  9. Appium+Python appium启动夜神模拟器定位元素(三)

随机推荐

  1. Day03
  2. 第三部分:Android 应用程序接口指南---第
  3. android 关于listview item设置高度的问
  4. Android Sensor传感器系统架构初探
  5. USB选择PTP功能时,如何同时显示内置、外置
  6. 初识Android
  7. Android智能电视应用程序开发浅谈(一)
  8. Linux与Android的关系
  9. android默认系统日期、时间、时区更改
  10. android 上面js java数据互传