I have the following 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"
android:orientation="horizontal" >
<RadioGroup
<!--stuff-->
</RadioGroup>
<Spinner
android:id="@+id/colour_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup1" />
<TextView
android:id="@+id/colourLabel"
android:text="@string/label_colour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup1"
android:layout_toLeftOf="@+id/colour_spinner"/>
<Spinner
android:id="@+id/country_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/colour_spinner" />
<TextView
android:id="@+id/countryLabel"
android:text="@string/label_country"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/colour_spinner"
android:layout_toLeftOf="@+id/country_spinner"/>
<Spinner
android:id="@+id/stadium_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/country_spinner" />
<TextView
android:id="@+id/stadiumLabel"
android:text="@string/label_stadium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/country_spinner"
android:layout_toLeftOf="@+id/stadium_spinner"/>
Hopefully it's obvious what I'm trying to do here. Three spinners, each below the one before, and a label to the left of each, ideally all lined up neatly.
The result I'm getting at the moment is that only the spinners show on the screen, and I get no text labels at all. What am I doing wrong here? I suspect it's to do with my layout width/height settings?
Enclose each spinner and label inside a horizontal 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">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<!-- stuff -->
</RadioGroup>
<LinearLayout
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/radioGroup"
android:orientation="horizontal" >
<TextView
android:id="@+id/colourLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_colour" />
<Spinner
android:id="@+id/colour_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/spinner2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner1"
android:orientation="horizontal" >
<TextView
android:id="@+id/countryLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/label_country" />
<Spinner
android:id="@+id/country_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/spinner2"
android:orientation="horizontal" >
<TextView
android:id="@+id/stadiumLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_stadium" />
<Spinner
android:id="@+id/stadium_spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With