[英]align a central button to bottom of screen
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代码如下
<?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: 像这样使用layout_alignParentBottom="true"
:
<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. 您必须在此处停止使用px。 It might be the reason for your problem. 这可能是您遇到问题的原因。 Simply try it like this using dip, 只需使用dip像这样尝试一下,
<Button
android:id="@+id/btnButton3"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_centerHorizontal="true"
android:text="..."/>
EDIT 1 编辑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: 像这样使用android:layout_centerInParent="true"
:
<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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.