Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 366
user1820528 Avatar asked Nov 14 '12 11:11

user1820528


1 Answers

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)

like image 145
reVerse Avatar answered Oct 13 '22 01:10

reVerse