Android How to put a RelativeLayout aligned to bottom?

在这里输入图像描述

I can show you in the prnt screen above the layout i actually have with my xml and the layout i pretend to have. I have made a few changes in the Relative Layout settings but cant solve it.

Here is the code:

@layout/gridview.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/BackGroundColor"
    android:orientation="vertical"
    android:scaleType="center" >

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginBottom="0dp"
        android:layout_marginLeft="0dip"
        android:layout_marginRight="0dip"
        android:background="@color/BlueOcean" />

    <GridView
        android:id="@+id/grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="4dp"
        android:columnWidth="100dp"
        android:horizontalSpacing="5dip"
        android:listSelector="@layout/gridview_selector"
        android:numColumns="3"
        android:padding="1dp"
        android:scaleType="fitCenter"
        android:stretchMode="columnWidth"
        android:verticalSpacing="4dp" />

    <RelativeLayout
        android:id="@+id/overviewBottomBar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="bottom"  
        android:gravity="top"    
        android:background="@layout/overviewbottombar_selector"
        android:textSize="14sp">

        <TextView
            android:id="@+id/overviewScreenLeft"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="39dp"
            android:text="Left"
            android:textColor="@color/holo_blue_dark" />

        <View
            android:id="@+id/overviewBottomBarDividerLeft"
            android:layout_width="1dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="39dp"
            android:layout_toRightOf="@+id/overviewScreenLeft"
            android:background="@color/darker_gray" />

        <TextView
            android:id="@+id/overviewScreenCenter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/overviewScreenLeft"
            android:layout_alignBottom="@+id/overviewScreenLeft"
            android:layout_centerHorizontal="true"
            android:text="Center"
            android:textColor="@color/holo_blue_dark" />

        <View
            android:id="@+id/overviewBottomBarDividerRight"
            android:layout_width="1dp"
            android:layout_height="32dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="38dp"
            android:layout_toRightOf="@+id/overviewScreenCenter"
            android:background="@color/darker_gray" />

        <TextView
            android:id="@+id/overviewScreenRight"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/overviewScreenCenter"
            android:layout_alignBottom="@+id/overviewScreenCenter"
            android:layout_alignParentRight="true"
            android:layout_marginRight="39dp"
            android:text="Right"
            android:textColor="@color/holo_blue_dark" />
    </RelativeLayout>

</LinearLayout>

Whats wrong with it?

Thanks


The problem is not the RelativeLayout but the LinearLayout that layouts it's children from top to bottom. The easiest way I can think of, is to add a spacer View with layout_weight="1" between the GridView and the RelativeLayout like so:

<GridView ... />

<!-- spacer view taking up all excess space -->
<View android:id="@+id/spacer"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

<RelativeLayout ... />

Make your root layout as RelativeLayout and you can set android:layout_alignParentBottom="true" for the RelativeLayout you have created with the id 'overviewBottomBar'. Then, it will be displayed at the bottom.


    <TextView
        android:id="@+id/overviewScreenLeft"
        android:layout_alignParentTop="true"

This is your problem. You want alignParentBottom="true"

链接地址: http://www.djcxy.com/p/93214.html

上一篇: 如何在屏幕底部显示小部件android

下一篇: Android如何把一个RelativeLayout对齐底部?