如何使的LinearLayout,滚动型,以填补整个区域(How to make the linea

2019-07-19 19:19发布

<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>

这是我的布局,我希望看到一个红色的背景(因为linear1有背景的红色和具有属性,以填补父),和另外两个人有超过绿色和蓝色bacgroudns的linear1布局

但我实际上看到的是从滚动视图和绿色,蓝色的linear2和linear3但linear1没有红色backgrund黑bacground

即线性充当像机器人:layout_height =“WRAP_CONTENT”被设定为不机器人:layout_height =“match_parent”

有任何想法吗 ?

Answer 1:

您需要设置fillViewport:

<ScrollView
    android:id="@+id/scrollView1"
    android:background="#000000"
    android:layout_width="match_parent"
    android:fillViewport="true" <!-- here -->
    android:layout_height="match_parent" >

    ...

 </ScrollView>

信息



文章来源: How to make the linearlayout in scrollview to fill the whole area