SANDHYA
SANDHYA

Reputation: 791

How to place a Linearlayout at bottom inside a Relativelayout in android

I need to place a linear layout at bottom inside a relativelayout which is the top most parent in xml. How can i do this?

Please help me.

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout .......   <<--- this should occupy total available space
</Relativelayout
 <Linearlayout .......     <<-- this should place at bottom always with height 50dp
 </LineaLayout>
 </ReltiveLayout>

Upvotes: 2

Views: 10706

Answers (4)

Shankar Agarwal
Shankar Agarwal

Reputation: 34765

Please try this:

<LinearLayout android:layout_alignParentBottom="true" android:layout_height="50dp" android:layout_width="wrap_content">
</LinearLayout>

you can align at bottom in xml from the above attribute.

Upvotes: 17

user3596220
user3596220

Reputation:

found more generic way to do this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".nestedLayoutActivity" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="seebelow" />

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

        <Button
            android:id="@+id/new_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="80dp"
            android:layout_gravity="bottom"
            android:text="@string/New" />

        <Button
            android:id="@+id/list_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:text="@string/list" />

        <Button
            android:id="@+id/more_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:text="@string/more" />
    </LinearLayout>


</RelativeLayout>

Upvotes: 0

NagarjunaReddy
NagarjunaReddy

Reputation: 8645

use this

 <?xml version="1.0" encoding="utf-8"?> 
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"      >
<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:background="#ff00ff00"
    android:layout_centerHorizontal="true" >
</RelativeLayout>
<LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="#ffff0000"
    android:layout_alignParentRight="true" >

</LinearLayout>

Upvotes: 0

Ant4res
Ant4res

Reputation: 1225

Try with this:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:minHeight="?android:attr/listPreferredItemHeight" >
 <RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="119dp" >
 </RelativeLayout>

 <LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" >
 </LinearLayout>

</RelativeLayout>

Upvotes: 0

Related Questions