线性布局的高度和宽度

7
我有以下内容。
<linearLayout>
<RelativeLayout>
    <!-- Header -->
</RelativeLayout>

<linearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="6">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    </LinearLayout>

</linearLayout>

然而,布局并没有正确地填满整个高度,我希望实现一个线性布局在另一个线性布局下方并占用父容器的1/6空间的效果。

相反,它似乎将权重应用于元素的宽度。

在Android中,假设百分比高度的正确方法是什么?使用Weight很容易实现宽度,但我似乎无法正确地实现高度。


2
在我看来没问题...哦,尝试在父级LinearLayout上指定orientation:vertical - Amokrane Chentir
我有同样的问题,但稍有不同。在我的情况下,根LinearLayout混合了LinearLayout、FrameLayout和RelativeLayout。你知道我哪里出错了吗?我已经在所有的LinearLayout中指定了方向。 - Jigish Chawda
1个回答

12

在你的LinearLayout中添加android:orientation="vertical",因为默认情况下它是android:orientation="horizontal"


它能工作,但在我的情况下:我有3个linerLayout嵌套在其他布局中,它们的高度不相同。 - Erik Lucio

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接