tags:

views:

51

answers:

2

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

+1  A: 

The Layout you want at the bottom should have:
android:gravity = "bottom"
and its parent should have:
android:layout_height="fill_parent"

fredley
I set the both above property Still layout is not at bottom of the screen
Sandy
@Sandy Is the parent layout the 'root' layout, i.e. it completely fills the screen? The child layout should also have `android:layout_height="wrap_content"`. Posting your code would help :-)
fredley
Yaa parent layout completely fill the screen.Child have android:layout_height="wrap_content"
Sandy
Can you post your xml in your question so we can see? Click the `edit` button below the question and paste it in.
fredley
My xml is same as above..I am unable to find out the mistake.Can you please tell me where i am wrong?
Sandy
Ah. Have a read [about android:layout_gravity vs android:gravity](http://stackoverflow.com/questions/3482742/android-gravity-and-layout-gravity)
fredley
I am using android:layout_gravity="bottom" which is used for layout so what is wrong?
Sandy
@Fredley Can you tell me the mistake?
Sandy
A: 

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: http://stackoverflow.com/questions/3555868/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>
sunadorer
Thanx for reply, But its not working with my layout.
Sandy
Have you already tried rewriting your xml in the way of my newer example? If it's not working maybe you can give more details on your wanted layout.
sunadorer