Reputation: 27399
I'm new to the layout structure in android and I'm tasked with building an activity that has a button at the bottom (centered horiz as well) with a small bit of padding between the bottom of the button and the bottom of the visible screen.
The challenge is how to do this in relative layout and make it anchor to the same spot regardless of screen size
If anyone can point me in the right direction that would be great!
Upvotes: 5
Views: 21713
Reputation: 13
You should be able to do this in the misc section of the button properties. Look for "Layout align parent bottom" and "Layout center horizontal". The button must be inside a relative layout that fills the entire screen for this method to work.
Upvotes: 0
Reputation: 9892
The dev docs have some sample layouts and the API Demos project is great too.
The layout below will put the button at the bottom, but remember as you add more controls to a relative layout they will have to respect each other. like layout_above this button or put this button at the end and make sure it has an attribute like android:layout_below="id_of_other_bottommost_controll"
<?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" >
<Button
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
android:text="button"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
Upvotes: 10