android对齐元素在屏幕的底部

时间:2012-08-20 09:16:15

标签: java android android-layout

我正在使用android:layout_alignParentBottom="true"在父级底部对齐,但对于此特定情况无效。父级是一种相对布局,其大小固定且屏幕高度更大。现在我需要在屏幕底部放置一个textview而不是父底部。怎么到达?谢谢。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="600dp" >

    <RelativeLayout
        android:id="@+id/blogLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <WebView
            android:id="@+id/webviewBlog"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textColor="@android:color/black" 
            android:scrollbars="none"
            android:fitsSystemWindows="true" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/Volver"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true">

        <TextView
            android:id="@+id/Volvertxt"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Volver"
            android:textColor="@android:color/white"
            android:textSize="30px"
            android:gravity="center"
            android:clickable="true"
            android:onClick="onClickVolver" />
    </RelativeLayout>

</RelativeLayout>

2 个答案:

答案 0 :(得分:1)

I have modified your code hope it solves your problem


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
   android:layout_height="fill_parent" >

        <WebView
            android:id="@+id/webviewBlog"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:textColor="@android:color/black" 
            android:scrollbars="none"
            android:fitsSystemWindows="true" />


        <TextView
            android:id="@+id/Volvertxt"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Volver"
            android:textColor="@android:color/white"
            android:textSize="30px"
            android:gravity="center"
            android:clickable="true"
            android:onClick="onClickVolver" />

</RelativeLayout>

答案 1 :(得分:0)

这是因为,您在父布局的dp个单位中给出了高度。设为match_parent

修改

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >


        <WebView
            android:id="@+id/webviewBlog"
            android:layout_width="fill_parent"
            android:layout_height="600dp"
            android:textColor="@android:color/black" 
            android:scrollbars="none"
            android:fitsSystemWindows="true" />



    <RelativeLayout
        android:id="@+id/Volver"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true">

        <TextView
            android:id="@+id/Volvertxt"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Volver"
            android:textColor="@android:color/white"
            android:textSize="30px"
            android:gravity="center"
            android:clickable="true"
            android:onClick="onClickVolver" />
    </RelativeLayout>

</RelativeLayout>