18

I'm trying to align a button to the bottom right and bottom left of my screen, using a RelativeLayout. I want to do this to keep the same relative layout across different screen sizes. Currently, the buttons on my screen move up/down depending on the resolution of the screen. 320x480 puts the buttons higher on the screen versus 480x800. I'm trying to get my screens to look the same between the two sizes.

2

4 Answers 4

56

I know this is an old thread but it shows up at the top of search results so I figure it can't hurt to confirm that

android:layout_alignParentBottom="true"  

worked for me in RelativeLayout.

5

Example:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:panel="http://schemas.android.com/apk/res/it.kronplatz"
    android:id="@+id/MainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <RelativeLayout
        android:id="@+id/ButtonLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_centerHorizontal="true"
        android:baselineAligned="false" >

        <ImageButton
            android:id="@+id/locateMeButton"
            android:layout_width="70px"
            android:layout_height="70px"
            android:layout_marginLeft="5px"
            android:src="@drawable/me" >
        </ImageButton>

        <ImageButton
            android:id="@+id/MapCenterButton"
            android:layout_width="70px"
            android:layout_height="70px"
            android:layout_alignParentRight="true"
            android:layout_gravity="right"
            android:layout_marginRight="5px"
            android:src="@drawable/fadenkreuz_klein" />

        <Button
            android:id="@+id/MapNextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/androidmarker" >
        </Button>
    </RelativeLayout>

</RelativeLayout>
5

Are you using android:layout_alignParent* ? That should justify it to a side regardless of screen size.

Where * is Bottom or Top or Left or Right

3

On addition what AedonEtLIRA said you should make sure that the RelativeLayout you have always filled the whole display area. ie. that you don't have any size defined in any place in the view hierarchy but instead match_parent is used. If you then used the layout definitions given by AedonEtLIRA you should get exactly what you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.