简体   繁体   中英

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>

在此处输入图片说明

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"

将以下内容添加到父级线性布局xml:

android:gravity="bottom"

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"
    />

Try Enclosing your ImageView in a Linear Layout and add

android:layout_alignParentBottom="true"

in your Relative Layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM