在ScrollView下加入的组件,不能自动扩展到屏幕高度

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

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

 1 例子,在ScrollView下加入的组件,无论如何也不能自动扩展到屏幕高度。
 2 
 3 布局文件。
 4 
 5 [html] 
 6 <?xml version="1.0" encoding="utf-8"?> 
 7 <!-- 背景:蓝色 --> 
 8 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
 9     android:id="@+id/scrollView1" 
10     android:layout_width="fill_parent" 
11     android:layout_height="fill_parent" 
12     android:background="#0000ff" > 
13  
14     <!-- 背景:绿色 --> 
15  
16     <LinearLayout 
17         android:id="@+id/linearLayout1" 
18         android:layout_width="fill_parent" 
19         android:layout_height="fill_parent" 
20         android:background="#00ff00" > 
21  
22         <TextView 
23             android:id="@+id/textView1" 
24             android:layout_width="wrap_content" 
25             android:layout_height="fill_parent" 
26             android:layout_weight="1" 
27             android:text="Hello Android." > 
28         </TextView> 
29     </LinearLayout> 
30  
31 </ScrollView> 

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


解决办法。

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

但如果scrollview里放个listview不行

原文地址:https://www.cnblogs.com/CharlesGrant/p/4727799.html