the_prole the_prole - 1 month ago 6
Android Question

How to fill space between two views within a RelativeLayout

I have two views. The top view is set to ...

android:layout_alignParentTop="true"


And the bottom is set to ...

android:layout_alignParentBottom="true"


How can I fill the remaining space with a third view? According to this answer here, I should use a frame layout like this ...

<FrameLayout
android:layout_below="@+id/toplayout"
android:layout_above="@+id/bottomlayout"/>


But then I am required to specify height and width. What height and width am I supposed to specify?

Answer

Here is my solution

<RelativeLayout
     ...
   >
        <YourLayout
         android:id="@+id/toplayout"
         android:layout_alignParentTop="true"
        />

        <YourLayout
         android:id="@+id/bottomlayout"
         android:layout_alignParentBottom="true"
        />

        <MiddleLayout // in your case it is FrameLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent" 
          // or android:layout_height="wrap_content" according to the_profile
           android:layout_below="@+id/toplayout" 
           android:layout_above="@+id/bottomlayout"/>
    </RelativeLayout>

Hope this help