Android 按钮对齐
我制作了一个相机布局,其中有两个按钮。一个是Android 按钮对齐,android,button,alignment,Android,Button,Alignment,我制作了一个相机布局,其中有两个按钮。一个是点击按钮,另一个是共享按钮 问题是我想让这个按钮在同一个视图中对齐,但我不能 这是我的按钮代码 <Button android:id="@+id/buttonClick" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click" android:layout_gravity="l
点击
按钮,另一个是共享
按钮
问题是我想让这个按钮在同一个视图中对齐,但我不能
这是我的按钮代码
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_gravity="left" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:layout_gravity="right" />
但是我希望
单击
按钮将与共享
按钮停留在同一个位置…您可能会将它们放置在线性布局中
以及其他视图(带有“Camera demo”文本)。但在看不到完整布局文件的情况下,您可以将它们包装到另一个布局中,如下所示:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:layout_alignParentRight="true" />
</RelativeLayout>
您可能会在另一个视图(带有“Camera demo”文本)中将它们放置在
线性布局中。但在看不到完整布局文件的情况下,您可以将它们包装到另一个布局中,如下所示:
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click"
android:layout_alignParentLeft="true" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Share"
android:layout_alignParentRight="true" />
</RelativeLayout>
从您的图像中,您的父布局使用垂直方向的线性布局。因此,添加到其中的每个视图都将在垂直方向上逐个放置
如果要将两个按钮放在同一行中,则必须使用RelativeLayout来包装这两个按钮。然后将孩子放在相对位置的左右两侧
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Share" />
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Click" />
</RelativeLayout>
从您的图像中,您的父布局使用垂直方向的线性布局。因此,添加到其中的每个视图都将在垂直方向上逐个放置
如果要将两个按钮放在同一行中,则必须使用RelativeLayout来包装这两个按钮。然后将孩子放在相对位置的左右两侧
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Share" />
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Click" />
</RelativeLayout>
应该还有一个RelativeLayout作为所有。。。。
这是我做的
<?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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Click" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Share" />
</RelativeLayout>
</RelativeLayout>
应该还有一个RelativeLayout作为所有。。。。
这是我做的
<?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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/buttonClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Click" />
<Button
android:id="@+id/buttonShare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Share" />
</RelativeLayout>
</RelativeLayout>
要更好地理解布局,请遵循以下步骤
在这里。根据你的问题,最好使用相对布局
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" //to assign botton to bottom of layout
>
要更好地理解布局,请遵循以下步骤
在这里。根据你的问题,最好使用相对布局
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" //to assign botton to bottom of layout
>
将它们放在水平线布局中当然,它们都放在一条水平线布局中。开发前阅读的好习惯,为您提供了解决方案,它解决了你的问题,但要了解更多信息,请深入阅读。将它们放在水平线布局中。当然,它们都放在一条水平线布局中。在开发之前阅读的好习惯,为你提供了解决方案。它解决了你的问题,但要了解更多信息,请深入阅读。