Reputation: 4472
In my screen layout contain a central button, i want to align that button to bottom of the screen. I tried with some code, but it became terrific...
my xml code as follows
<?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:id="@+id/btnButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>
<RelativeLayout
android:id="@+id/belowLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/btnButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Left"/>
<Button
android:id="@+id/btnButton3"
android:layout_width="75px"
android:layout_height="50px"
android:layout_centerHorizontal="true"
android:text="..."/>
<Button
android:id="@+id/btnButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
</RelativeLayout>
screen shot
thanks
Upvotes: 0
Views: 10465
Reputation: 1500
Use android:layout_centerInParent="true"
like this:
<Button
android:id="@+id/btnButton3"
android:layout_width="75px"
android:layout_height="50px"
android:layout_marginTop="10dp"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:text="..."/>
Upvotes: 2
Reputation: 4400
<Button
android:id="@+id/btnButton3"
android:layout_width="75px"
android:layout_height="50px"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_gravity="center_vertical|center_horizontal"
android:text="..."/>
Upvotes: 1
Reputation: 506
Try this
<Button
android:id="@+id/btnButton3"
android:layout_width="75px"
android:layout_height="50px"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@+id/btnButton2"
android:text="..."/>
Upvotes: 5
Reputation: 54322
You have to stop using px here. It might be the reason for your problem. Simply try it like this using dip,
<Button
android:id="@+id/btnButton3"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_centerHorizontal="true"
android:text="..."/>
EDIT 1
<Button
android:id="@+id/btnButton3"
android:layout_width="75dip"
android:layout_height="25dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="..."/>
dip-density independent Pixels.
Here is the output,
Upvotes: 2
Reputation: 16043
Add android:layout_alignParentBottom="true"
for the "@+id/btnButton3"
Upvotes: 0
Reputation: 4354
Use layout_alignParentBottom="true"
like this:
<Button
android:id="@+id/btnButton3"
android:layout_width="75px"
android:layout_height="50px"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="..."/>
Upvotes: 8