10

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

Sandy
  • 6,285
  • 15
  • 65
  • 93

6 Answers6

20

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>
Community
  • 1
  • 1
sunadorer
  • 3,855
  • 34
  • 42
  • 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 Oct 28 '10 at 12:46
11

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

fredley
  • 32,953
  • 42
  • 145
  • 236
  • I set the both above property Still layout is not at bottom of the screen – Sandy Sep 27 '10 at 09:11
  • @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 Sep 27 '10 at 09:13
  • Yaa parent layout completely fill the screen.Child have android:layout_height="wrap_content" – Sandy Sep 27 '10 at 09:15
  • Can you post your xml in your question so we can see? Click the `edit` button below the question and paste it in. – fredley Sep 27 '10 at 09:20
  • My xml is same as above..I am unable to find out the mistake.Can you please tell me where i am wrong? – Sandy Sep 27 '10 at 09:21
  • Ah. Have a read [about android:layout_gravity vs android:gravity](http://stackoverflow.com/questions/3482742/android-gravity-and-layout-gravity) – fredley Sep 27 '10 at 09:24
  • I am using android:layout_gravity="bottom" which is used for layout so what is wrong? – Sandy Sep 27 '10 at 09:27
1
<Linearlayout android:layout_height="fill_parent" 
android:orinationtation="vertical"
android:layout_width="fill_parent">

<RelativeLayout  android:layout_height="0dp" 
android:layout_width="fill_parent"
android:weight="1">
</RelativeLayout>

<RelativeLayout 
android:layout_height="0dp" 
android:layout_width="fill_parent"
android:weight="1"
>   
</RelativeLayout>



</Linearlayout >
Teraiya Mayur
  • 1,094
  • 10
  • 18
1

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"
    />
IDontEvenKnow
  • 122
  • 1
  • 1
  • 9
1

Try using:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="#ffb3e5fc"
   android:id="@+id/linearLayout1">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom">
<Button
    android:id="@+id/button1"
    android:text="Left"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_toLeftOf="@+id/centerPoint" />
<TextView
    android:id="@+id/centerPoint"
    android:text=""
    android:layout_width="1dip"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true" />
<Button
    android:id="@+id/button2"
    android:text="Right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/centerPoint" />
</RelativeLayout>
</LinearLayout>

It produces something that looks like this

Laurel
  • 5,965
  • 14
  • 31
  • 57
bitles
  • 11
  • 2
0

For my it's work.

    <RelativeLayout
    android:id="@+id/InnerRelativeLayout"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="#fff"
    android:gravity="bottom"
    app:layout_anchor="@+id/fab_inout"
    app:layout_anchorGravity="bottom|center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="dsfsdfasdf df" />

</RelativeLayout>
Blazej Kita
  • 99
  • 1
  • 1
  • 10