Linear Layout Height and Weight

19,545

add android:orientation="vertical" in your LinearLayout as by default it is android:orientation="horizontal".

Share:
19,545
Xavier
Author by

Xavier

Updated on June 04, 2022

Comments

  • Xavier
    Xavier almost 2 years

    I have the following

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

    However the layouts are not assuming to fill the height properly I wish to for the desired effect of one linearLayout below another and to take up 1/6th of the parent space.

    Instead it seems to be applying the weight to the width of the element.

    What is the correct method to assume percentage height in Android? Width seems to be a breeze with Weight but I can't seem to get it correct on Height.