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
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="..."/>
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="..."/>
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,
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="..."/>
<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="..."/>
为"@+id/btnButton3"
添加android:layout_alignParentBottom="true"
"@+id/btnButton3"
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.