Search code examples
androidandroid-layoutlayoutandroid-linearlayoutfill-parent

LinearLayout android layout_height


Help me with XML layout.

I have three LinearLayout on activity, all LinearLayout have position vertical (from top to bottom)

My LinearLayout positions

  1. first LinearLayout have android:layout_height="30px", android:layout_width="fill_parent"
  2. second LinearLayout have android:layout_height="fill_parent", android:layout_width="fill_parent"
  3. third LinearLayout have android:layout_height="30px",android:layout_width="fill_parent"

But when second LinearLayout set as fill_parent it fill full screen (from first Layout to bottom of screen), and third LinearLayout cant display!

How i need fill the second layout?

Help me


Solution

  • You can use relative layout for your purpose:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >
    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >
    </LinearLayout>
    
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout1"
        android:layout_above="@+id/linearLayout2"
        android:orientation="vertical" >
    </LinearLayout>
    
    </RelativeLayout>