<Button android:id="@+id/btn_data" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="编辑资料" android:layout_marginTop="10dp" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回主页" android:layout_marginTop="10dp" android:layout_ />如何让第二个按钮放于第一个按钮右边
时间: 2024-02-27 20:57:24 浏览: 23
可以使用 LinearLayout 布局,将两个按钮都放在 LinearLayout 中,然后设置第一个按钮的 layout_weight 属性为 1,第二个按钮的 layout_weight 属性为 0,这样第一个按钮会占据更多的宽度,第二个按钮会紧贴其右侧。具体代码如下:
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btn_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="编辑资料"
android:layout_marginTop="10dp"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回主页"
android:layout_marginTop="10dp"
android:layout_weight="0" />
</LinearLayout>
```