nishantvodoo
nishantvodoo

Reputation: 865

Stretch and fill middle Layout Android

I have a Main Relative Layout(height,width=fill parent) that has 3 layouts inside it:

1st: Frame Layout(width=fill_parent/height=wrap_content)
2nd: Linear Layout(width=fill_parent/height=wrap_content/layoutbelow 1st)
3rd: Relative Layout(height=wrap_content/width=fill parent/layout_alignParentBottom="true"/ layoutbelow 2nd)

I want the 3rd layout to be at the bottom of the screen and 1st at the top of the screen and 2nd to fill the space in between. How do I do this? I followed this link:Android LinearLayout fill-the-middle and tried setting layout_height="0px" and layout_weight="1" but it did not work. Can anyone please help me with this?

Thanks

Upvotes: 2

Views: 3073

Answers (2)

SANAT
SANAT

Reputation: 9257

Try this :

1st: Frame Layout(width=fill_parent/height=wrap_content)

2nd: Linear Layout(width=fill_parent/height=wrap_content/layoutbelow 1st/layoutabove 3rd)

3rd: Relative Layout(height=wrap_content/width=fill parent/layout_alignParentBottom="true")

For Example :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/btnButton1"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="1"/>

    <Button
        android:id="@+id/btnButton2"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="2"
        android:layout_below="@+id/btnButton1"
        android:layout_above="@+id/btnButton3"/>

    <Button
        android:id="@+id/btnButton3"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="3"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>

Screenshot

Upvotes: 3

pelotasplus
pelotasplus

Reputation: 10052

IIRC RelativeLayout doesn't support layout_weight.

So you need something like this:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_wight="1" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

Upvotes: 6

Related Questions