How to make the linearlayout in scrollview to fill

2019-03-12 02:34发布

<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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-12 03:19

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

查看更多
登录 后发表回答