如何在Android的RelativeLayout中对齐微调器视图?

如何在Android的RelativeLayout中对齐微调器视图?,android,android-layout,android-ui,Android,Android Layout,Android Ui,我试图将微调器置于相对布局的中心。 我的尝试如下: <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center"> <Spinner a

我试图将微调器置于相对布局的中心。 我的尝试如下:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center">

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/typesSpinner"/>

    </LinearLayout>

这在其他情况下对我很有效,但在spinner中不行。
为什么?

假设您确实想要一个
相对性布局,而不是
线性布局
作为包装器。以下方面应起作用:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Spinner
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

</RelativeLayout>

假设您确实想要一个
相对布局
而不是
线性布局
作为包装器。以下方面应起作用:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Spinner
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"/>

</RelativeLayout>


您提到尝试将其置于相对位置,但您的示例使用的是线性布局。我实际上是想使用线性布局,因为我已经习惯了。我不知道相对布局有那么简单,你提到要把它放在相对布局的中心,但你的例子是使用线性布局。我实际上是想使用线性布局,因为我已经习惯了。我不知道相对布局有那么简单你也可以只使用android:layout\u centerInParent=“true”
@XaverKapeller是的,一行肯定比两行好,我会更新我的答案我实际上想使用线性布局,但因为相对布局很容易,我不介意。谢谢你也可以使用android:layout\u centerInParent=“true”@XaverKapeller是的,一行肯定比两行好,我会更新我的回答我实际上想使用线性,但是因为它与相对来说很容易工作,我不介意。谢谢