首页 > 解决方案 > 拆分滚动视图,使其拉伸一半的屏幕,但它忽略了布局权重

问题描述

我正在尝试创建一个显示在屏幕上半部分的垂直滚动视图,下半部分将有几个按钮。

我有一个垂直线性布局,其中有两个垂直线性布局(顶部包含滚动视图),并将两个线性布局中的每一个设置为布局权重为 1,但滚动视图无论如何都会延伸超过页面的一半。

<LinearLayout
    android:id="@+id/mainlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:orientation="vertical">

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:background="@drawable/b_whitetrans4">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:fadeScrollbars="false"
            android:scrollbarThumbVertical="@android:color/holo_red_dark">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="5dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/settingtext"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:text="asdfasdfasdfasdfasdf"
                    android:textColor="@android:color/white"
                    android:textSize="20sp" />

            </LinearLayout>

        </ScrollView>
    </LinearLayout>

    <LinearLayout
        android:layout_weight="1"
        android:id="@+id/buttonlayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


    </LinearLayout>


</LinearLayout>

奇怪的是,滚动视图并没有一直拉伸以显示所有内容,但它肯定超过了屏幕的一半。这就是发生的事情: https ://www.screencast.com/t/VPHJwPhpLyb

标签: javaandroid

解决方案


将顶部 LinearLayout 的高度设置为match_parent并删除layout_weight下部的属性。


推荐阅读