簡體   English   中英

如何在Android的RelativeLayout中對齊微調框視圖?

[英]How to align spinner view inside RelativeLayout in Android?

我試圖將微調器設置在相對布局的中心。 我的嘗試如下:

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

在其他情況下,這對我來說效果很好,但不適用於微調器。 為什么?

假設您實際上需要RelativeLayout而不是LinearLayout作為包裝器。 以下應該工作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM