Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: relative layout, put an element at the bottom

Hello i have this layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
    android:src="@drawable/head"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:id="@+id/image1"
     />
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/scan"
    android:text=""
    android:layout_below="@+id/image1" />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/mio_ad">
</LinearLayout>
</RelativeLayout>

there's no way i can put my #mio_ad at the bottom: it remains at the top. how can i? thanks.

like image 487
Zak Avatar asked Jul 11 '12 07:07

Zak


People also ask

How do you align at the bottom of relative layout?

If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.

How do I fix the bottom layout on my android?

You can set the layout_height="0dp" of your header, footer and ScrollView and define a layout_weight . Just play around with the values until you find out which works best. The resulting heights of header and footer would dynamically change with the screensize.

Which is better linear layout or relative layout?

LinearLayout is less used as compared to RelativeLayout. RelativeLayout is used more in applications. We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.

Is Relative layout deprecated?

@filthy_wizard: RelativeLayout is not deprecated. PercentRelativeLayout is deprecated.


2 Answers

android:layout_alignParentBottom="true"

use it!

like image 51
Ilya Demidov Avatar answered Sep 17 '22 04:09

Ilya Demidov


Use Below XML Code for that, it may help you.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/llayout" 
        android:layout_above="@+id/mio_ad">
        <ImageView
            android:src="@drawable/head"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:id="@+id/image1"/>
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/scan"
            android:text=""
            android:layout_below="@+id/image1" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/mio_ad" 
        android:layout_alignParentBottom="true" >

    </LinearLayout>
</RelativeLayout>
like image 27
Dipak Keshariya Avatar answered Sep 19 '22 04:09

Dipak Keshariya