Android 如何对齐按钮?

Android 如何对齐按钮?,android,android-layout,Android,Android Layout,安卓系统中的按钮如何对齐,使其上、下和按钮之间具有适当的间距 当前代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <include android:id="@

安卓系统中的按钮如何对齐,使其上、下和按钮之间具有适当的间距

当前代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<include 
     android:id="@+id/ActionBackupBar"
     layout="@layout/actionbar_layout" 
    />



使用RelativeLayout而不是LinearLayout。 然后您可以轻松地对齐按钮


希望这能对您有所帮助。

更改为RelativeLayout,然后尝试以下操作:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<Button
    android:id="@+id/btnSelectLocation"
    style="@style/ButtonText"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:text="text1" />
<Button
    android:id="@+id/btnCurrentLocation"
    style="@style/ButtonText"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/btnSelectLocation"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:text="test2" />
</RelativeLayout>

1。填充父项已弃用,请使用匹配父项。2.将sp用于边距没有意义。改用dp。3.你想要实现什么?您希望如何对齐这些按钮?如图所示?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">

<Button
    android:id="@+id/btnSelectLocation"
    style="@style/ButtonText"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:text="text1" />
<Button
    android:id="@+id/btnCurrentLocation"
    style="@style/ButtonText"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/btnSelectLocation"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:text="test2" />
</RelativeLayout>