Search code examples
androidandroid-linearlayoutandroid-framelayout

Two frame layouts inside linear layout


This is the code I have now:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/tablet_locations_fragment_locations_fragment_list_container"
        android:layout_width="match_parent"
        android:layout_height="90dp" />

</LinearLayout>

I think it's clear that I want bottom frame layout to be 90dp high and upper to take the rest of the space, but currently, upper frame layout is taking all of the screen height. How can I fix this? I tried to put layout_height="wrap_content" for upper frame layout, but it's not changing anything.


Solution

  • layout_weight is your friend

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <FrameLayout
            android:id="@+id/tablet_locations_fragment_fragment_container"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp" />
    
        <FrameLayout
            android:id="@+id/tablet_locations_fragment_locations_fragment_list_container"
            android:layout_width="match_parent"
            android:layout_height="90dp" />
    
    </LinearLayout>