[英]Align buttons to the bottom of the layout
i want to align two buttons to the bottom of the screen as follows. 我想将两个按钮对齐到屏幕底部,如下所示。 i tried the xml given in this similar question but no luck.how to do it ?
我尝试了这个类似问题中给出的xml,但是没有运气。该怎么办?
like this - 像这样 -
this should be without the spacing in the bottom 这应该在底部没有间距
This is the property you need to use: 这是您需要使用的属性:
android:layout_alignParentBottom="true"
Try using the following XML and customize your button appearance as you like: 尝试使用以下XML并根据需要自定义按钮外观:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d1000000"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="PREV"
android:layout_marginRight="-5dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="NEXT"
android:layout_marginLeft="-5dp"/>
</LinearLayout>
</RelativeLayout>
I do not have the reputation necessary to comment on the response aashima 我没有评论回应aashima所需的声誉
but I think you also have to add android:weightSum="2"
但我认为您还必须添加
android:weightSum="2"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="PREV"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="NEXT"/>
You can also create an invisible variable to initialize the others on the layout . 您还可以创建一个不可见变量来初始化布局上的其他变量。
For example, create an ImageView and make it invisible . 例如,创建一个ImageView并使它不可见。 After this center it vertically .
在此中心之后垂直。 You can also choose the height to match parent .
您也可以选择高度以匹配父级。 So in the middle of the screen (vertically) there will be an ImageView .
因此,在屏幕中间(垂直)将出现一个ImageView。 You can also set the width to 0,1 or more it depends on what you want and what kind of images you have
您还可以将宽度设置为0.1或更大,具体取决于您想要的内容和所拥有的图像类型
After you create it , for 'Previous' button you can choose AlignLeft option and choose this ImageView . 创建它之后,对于“上一个”按钮,您可以选择AlignLeft选项,然后选择此ImageView。 For 'Next' button you can choose AlignRight and show this ImageView again .
对于“下一步”按钮,您可以选择AlignRight并再次显示此ImageView。
With this trick the buttons always will be mirrored to each other on the screen . 使用此技巧,按钮将始终在屏幕上彼此镜像。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="bottom|center"
>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="before"
android:layout_toLeftOf="@+id/i"
android:layout_gravity="bottom|left" />
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:onClick="after"
android:layout_gravity="bottom|right"/>
</LinearLayout>
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.