techno
techno

Reputation: 6518

Align Relative Layout at bottom of Linear Layout in Parent

I have Linear Layout which acts as the parent of a Relative layout.The Relative layout consists of some buttons and stuff.I want to align the relative layout(panel containing buttons) at the bottom of the linear layout.The linear layout only consists of an ImageView and after that the relative layout should be aligned at the bottom.

But when i try to set android:layout_alignParentBottom="true" in the Relative Layout the IDE Prompts code is wrong.How can i achieve this please help

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="250dp"
        android:scaleType="fitStart"
        android:src="@drawable/jellyfish" />

    <RelativeLayout

        android:layout_width="318dp"
        android:layout_height="164dp"
        android:layout_margin="5dp"
        android:background="@drawable/backgrad"
        android:orientation="vertical" >

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="34dp"
            android:onClick="clickme"
            android:text="Button" />

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginTop="16dp"
            android:layout_toLeftOf="@+id/button1"
            android:onClick="textclick"
            android:src="@drawable/text" />

        <Button
            android:id="@+id/button2"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/button1"
            android:layout_alignBottom="@+id/button1"
            android:layout_centerHorizontal="true"
            android:onClick="wmark"
            android:text="Save" />


    </RelativeLayout>

</LinearLayout>

enter image description here

Upvotes: 0

Views: 10231

Answers (4)

Mayank Gaur
Mayank Gaur

Reputation: 11

Try Enclosing your ImageView in a Linear Layout and add

android:layout_alignParentBottom="true"

in your Relative Layout.

Upvotes: 0

IDontEvenKnow
IDontEvenKnow

Reputation: 122

I have answered another topic like this, solution is to put a View with weight 1 above your relative layout like this:

    <View android:id="@+id/emptySpace"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

Upvotes: 0

mithrop
mithrop

Reputation: 3363

Possible duplicate : How to achieve alignParentBottom="true" property in LinearLayout

When you set android:layout_alignParentBottom="true", you are trying to use methods of the LinearLayout. But LinearLayout DO NOT provide alignParentBottom.

The answer in the duplicate says to replace

android:layout_alignParentBottom="true"

by

android:gravity="bottom"

Upvotes: 1

Ken
Ken

Reputation: 31171

Add the following to your parent linear layout xml:

android:gravity="bottom"

Upvotes: 0

Related Questions