Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 布局重量,以获得2个等高布局_Android_User Interface - Fatal编程技术网

Android 布局重量,以获得2个等高布局

Android 布局重量,以获得2个等高布局,android,user-interface,Android,User Interface,我目前正在修改一个xml布局,我想将所有视图分为两个部分,每个部分的高度为可用高度的一半。布局如下所示: <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > ...Lots of stuff... </LinearLayout> 我所做的是将视图的

我目前正在修改一个xml布局,我想将所有视图分为两个部分,每个部分的高度为可用高度的一半。布局如下所示:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>   

    ...Lots of stuff...

</LinearLayout>
我所做的是将视图的每一半包装成一个线性布局,并为每个视图指定一个权重

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>  

    <!-- Top half -->
    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="fill_parent"
        android:orientation="vertical">

        ... stuff and things ...

    </LinearLayout>

    <!-- Bottom half -->
    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="fill_parent"
        android:orientation="vertical">

        ... things and stuff ...

    </LinearLayout>

</LinearLayout>

我不明白为什么这不能给我两个相等的窗格。较低的一个似乎占据了90%的可用空间。我尝试将android:weightSum=2添加到容器布局中,但没有效果。这些布局都没有ID,因此隐藏的代码应该无法修改它们。知道这是怎么回事吗?子视图是否能够修改其半容器,使其看起来不相等?

此链接可能对您有所帮助:


您所做的似乎是正确的,但可能是线性布局中的内容造成的。

尝试向父线性布局添加权重和,如下所示:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="2">  

    <!-- Top half -->
    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:orientation="vertical">

        ... stuff and things ...

    </LinearLayout>

    <!-- Bottom half -->
    <LinearLayout
        android:layout_weight="1"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:orientation="vertical">

        ... things and stuff ...

    </LinearLayout>

</LinearLayout>

此外,我还更改了子项的布局高度:子项LinearLayouts不需要填充父项,因为父项已经具有该属性。

您的布局文件似乎没有问题。您正在添加什么内容?有图像吗?有很多东西。有用于按钮图标和背景的图像,但与布局大小相比,它们实际上无关紧要。看起来我必须重新开始,开始将内容逐块转移到新的布局中。