How to fill space between two views within a RelativeLayout
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
You could take an advantage of weighting. android:layout_weight
property usually fills whatever space is left (or split equally). In your case it would be something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="some_fixed_height"
android:orientation="vertical">
<LinearLayout
android:id="@+id/top_one"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/middle_one_that_fills"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/bottom_one"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
As long as your root layout is a RelativeLayout and you're using layout_alignParentTop
for the top view and layout_alignParentBottom
for the bottom view, like you mentioned, then it should be working with no need for a middle view:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Alternatively, if your root view is a LinearLayout, you could use the lesser-known, but aptly-named Space view. Space is:
a lightweight View subclass that may be used to create gaps between components in general purpose layouts.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"/>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>