<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" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="返回主页" android:layout_marginTop="10dp" />如何让第一个按钮在最左边,第二个按钮在最右边
时间: 2024-02-27 17:57:31 浏览: 22
可以在第一个按钮和第二个按钮之间加入一个空的 View,然后设置这个 View 的 layout_weight 属性为 1,这样第一个按钮和第二个按钮的宽度都会被限制,而这个空的 View 会填充剩余的空间,从而让第一个按钮在最左边,第二个按钮在最右边。具体代码如下:
```
<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" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回主页"
android:layout_marginTop="10dp" />
</LinearLayout>
```