简体   繁体   中英

android align element at bottom of the screen

I am using android:layout_alignParentBottom="true" to align at parent bottom but for this particular case is not valid. Parent is a relative layout that has fixed size and bigger that screen height. Now I need to place a textview aligned at bottom of screen and not parent bottom. How to reach it? thank you.

<?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>
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>

That is because, you are giving height in dp units of the parent layout. Make it match_parent .

EDIT :

<?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>

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