Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place Relative layout at bottom of screen(or linear layout).?

Tags:

android

I have following in xml

I wanna put the second linear layout at the bottom of the screen. How will i do? I have set the property of second Relative layout to bottom but still not showing at bottom..

**

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent">    
<RelativeLayout android:id="@+id/RelativeLayout01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">   
</RelativeLayout>
<RelativeLayout android:id="@+id/RelativeLayout02" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">   
</RelativeLayout>
<RelativeLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
    android:layout_gravity="bottom">
</RelativeLayout>
</LinearLayout>

** Thanx in advance

like image 790
Sandy Avatar asked Sep 27 '10 09:09

Sandy


1 Answers

I was searching for this a while too. My just found solution is to use the property:

android:layout_alignParentBottom="true"

instead of your existing android:layout_gravity="bottom"

This unfortunately with my layout only works when having an additional RelativeLayout as root layout and the rest added to it. Maybe this is not always the case, but with having a LinearLayout (even when told to use fill_parent) it only used the height all added elements needed and put my footer at the bottom of those.

I came to this solution, looking at this related question: How do I achieve the following result using RelativeLayout?

EDIT here because format in answer comment got lost: Do you mean you can't re-write it or that it didn't work?

I had a vertical LinearLayout too and my new xml structure looks (without the layout size params etc.) sth. like this:

<RelativeLayout>
    <RelativeLayout 
        android:id="@+id/RelativeLayout01">
    </RelativeLayout>
    <RelativeLayout 
        android:id="@+id/RelativeLayout02" 
        android:layout_below="@+id/RelativeLayout01">   
    </RelativeLayout>
    <RelativeLayout 
        android:layout_below="@+id/RelativeLayout02" 
        android:layout_alignParentBottom="true">
    </RelativeLayout>
</RelativeLayout>
like image 65
sunadorer Avatar answered Sep 17 '22 12:09

sunadorer