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

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


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


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>

You should put a View before your last layout with weight 1, and it will put it to bottom. Like this:

    <View android:id="@+id/emptySpace"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />
链接地址: http://www.djcxy.com/p/93316.html

上一篇: Android:将按钮文本移动到底部

下一篇: 如何将相对布局放置在屏幕底部(或线性布局)。