问题
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/scrollView1"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linear1"
android:background="#FF0000"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:background="#00FF00"
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="200dip"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:background="#0000FF"
android:id="@+id/linear3"
android:layout_width="match_parent"
android:layout_height="100dip"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
This is my layout and I expected to see a red background (because linear1 have background red and have properties to fill the parent) , and two others layout with over the linear1 with green and blue bacgroudns
but what I actually see is black bacground from the scrollview and green and blue from linear2 and linear3 but no red backgrund from linear1
namely the linear is acting like android:layout_height="wrap_content" is set not android:layout_height="match_parent"
any ideas ?
回答1:
You need set fillViewport:
<ScrollView
android:id="@+id/scrollView1"
android:background="#000000"
android:layout_width="match_parent"
android:fillViewport="true" <!-- here -->
android:layout_height="match_parent" >
...
</ScrollView>
information
来源:https://stackoverflow.com/questions/14837983/how-to-make-the-linearlayout-in-scrollview-to-fill-the-whole-area