How to fill in the gap between two views in RelativeLayout

I have two kinds. Top view set to ...

 android:layout_alignParentTop="true"

And below is set to ...

 android:layout_alignParentBottom="true"

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

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

But then I need to specify the height and width. What height and width should I indicate?

+6
source share
3 answers

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 helps

+11
source

. android:layout_weight ( ). :

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

RelativeLayout, layout_alignParentTop layout_alignParentBottom , , :

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

, LinearLayout, , Space. :

View, .

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

Source: https://habr.com/ru/post/1616145/


All Articles