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?
Use the setPadding(left, top, right, bottom) method on the view to set the padding. The integers passed as parameters to this function are the number of pixels (px), which are different from the density-independent pixels (dp or dip).
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.
Basically, it is used to display more views neatly on the screen. A RelativeLayout is a common type of ViewGroup that lets us position child views relative to sibling elements (such as to the left-of or below another view) or relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With