Android 安卓:如何将两个全宽按钮居中放置?

Android 安卓:如何将两个全宽按钮居中放置?,android,android-layout,Android,Android Layout,如何使两个按钮像图像一样居中 很简单!我们走吧 <Button android:id="@+id/btnSetDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_weight="1.0"

如何使两个按钮像图像一样居中


很简单!我们走吧

<Button
        android:id="@+id/btnSetDate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="1.0"
        android:text="Set Date" />

 <Button
    android:id="@+id/btnSetTime"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_weight="1.0"
    android:text="Set Time" />

很简单!我们走吧

<Button
        android:id="@+id/btnSetDate"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_weight="1.0"
        android:text="Set Date" />

 <Button
    android:id="@+id/btnSetTime"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_weight="1.0"
    android:text="Set Time" />

只需将您的按钮包装成一个内容,如linearlyout,使用android:gravity=“center\u vertical”即可

<?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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btnSetDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Set Date" />

        <Button
            android:id="@+id/btnSetTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Set Time" />

    </LinearLayout>

</RelativeLayout>

只需将您的按钮包装成一个内容,如linearlyout,使用android:gravity=“center\u vertical”即可

<?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" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical" >

        <Button
            android:id="@+id/btnSetDate"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Set Date" />

        <Button
            android:id="@+id/btnSetTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Set Time" />

    </LinearLayout>

</RelativeLayout>