简体   繁体   中英

Android layout : Align a TextView and a Spinner

I would like to align a textview (saying : "Day :") with a Spinner where the user can choose the day of the week he wants (Monday, Tuesday, etc.)

when I try to align them :

 <TextView android:id="@+id/labelSpinner1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/textSpinner1"
                    android:layout_toRightOf="@+id/spinner_days"
                    android:layout_alignParentTop="true"/>

                <Spinner android:id="@+id/spinner_days"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/labelSpinner1"
                    android:layout_alignParentLeft="true"
                    android:drawSelectorOnTop="true"/>

the result I get is that I only see the Spinner, and the TextView isn't showing (or is underneath the Spinner)

Thank you for your help!

I guess you want the Spinner to the right of the TextView? Check the following code:

<TextView
    android:id="@+id/labelSpinner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:text="@string/textSpinner1" />

<Spinner
    android:id="@+id/spinner_days"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@id/labelSpinner1"
    android:layout_toRightOf="@id/labelSpinner1"
    android:drawSelectorOnTop="true" />

Your problem was that the spinner filled the whole view ( android:layout_width="fill_parent" ) while you forced the TextView to be right of the Spinner (so outside of the screen --> invisible for you)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM