为什么RelativeView不会到底?

时间:2011-07-11 05:51:21

标签: android layout android-layout

具体来说,我试图让具有id bottomStuff的RelativeLayout向下浮动。我尝试将重力设置设置为底部,这是从其他SO帖子中提出的,但它仍然一直保持在顶部,为什么会这样?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/relativeLayout1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">

<TextView android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge"
    android:layout_alignParentRight="true" android:layout_weight="1"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:text="@string/currentAlarms" android:gravity="center"
    android:layout_alignParentTop="true">
</TextView>

<ScrollView android:id="@+id/scroll" android:layout_width="fill_parent"
    android:layout_below="@+id/textView1" android:layout_centerVertical="true"
    android:gravity="center" android:layout_height="wrap_content"
    android:layout_marginBottom="150px">

    <LinearLayout android:layout_width="wrap_content"
        android:id="@+id/alarms" android:orientation="vertical"
        android:gravity="center" android:layout_centerVertical="true"
        android:layout_height="wrap_content">
    </LinearLayout>
</ScrollView>

<RelativeLayout android:id="@+id/bottomStuff"
android:layout_height="wrap_content" android:layout_width="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true" android:layout_marginBottom="12dp"
    android:gravity="bottom">

<com.google.ads.AdView android:id="@+id/adView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     ads:adUnitId="a14e1a859cbb3fb"
                     ads:adSize="BANNER"
                     ads:loadAdOnCreate="true"/>

        <LinearLayout android:id="@+id/BLinearLayout"
        android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:layout_below="@+id/adView"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:gravity="bottom">

        <Button android:layout_height="wrap_content" android:text="@string/addAlarm"
            android:id="@+id/button1" android:layout_width="0px"
            android:layout_weight="1" android:drawableTop="@drawable/plus"
            android:onClick="addAlarm">
        </Button>
        <Button android:layout_width="0px" android:layout_height="wrap_content"
            android:id="@+id/button2" android:layout_centerVertical="true"
            android:layout_alignParentRight="true" android:layout_weight="1"
            android:text="@string/settings" android:drawableTop="@drawable/preferences">
        </Button>

    </LinearLayout>
</RelativeLayout>

</RelativeLayout>

谢谢!

3 个答案:

答案 0 :(得分:2)

在带有按钮的LinearLayout中,删除layout_alignParentBottom:

<LinearLayout android:id="@+id/BLinearLayout"
        android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:layout_below="@+id/adView"
        android:layout_centerHorizontal="true"
        android:layout_gravity="bottom">

答案 1 :(得分:0)

尝试将layout_gravity更改为gravity。

答案 2 :(得分:0)

你的XML搞砸了,我看到RelativeLayout的两个开放标签,但只有一个关闭标签,你试过干净吗?这应该会产生错误