In my application I've got 3 spinners - one on the top, which when used provides the user with 2 more aligned below it.
I looked at this question where I found the answer I was looking for, but only half-way.. Now the two supplementary spinners have their text shown in the center, but the first one - no.
Looking at the .xml for the spinners I can see only one difference regarding to centering and it is that the two supplementary ones have the android:layout_gravity="center"
attribute, which for some reason is not applicable to the first spinner. Why is this so? Could this be the reason? By not applicable I mean it is not in the properties for the spinner in the design view and when I add it manually in the .xml nothing changes.
So ideally the answer which I am looking for is why the 2 supplementary spinners have their text centered, but the first one - no? Note I am not interested in centering the elements in the popup, this is purely optional. I just want to have the selected option to be in the center.
Here is a screenshot of how it looks now with the problem in red:
Here is the .xml
I am using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/some_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="packagename"
tools:showIn="@layout/specific_activity_layout"
android:gravity="center_horizontal"
android:background="#FF9800">
<Spinner
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="@+id/spinner1"
android:entries="@array/spinner1entries"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:gravity="center|top"
android:background="@drawable/rounded_corners"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:popupBackground="#FFB74D"
android:layout_alignParentEnd="false"
android:textAlignment="center" />
<LinearLayout
android:id="@+id/horizontal_layout_spinners"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false"
android:visibility="invisible"
android:layout_below="@+id/spinner1">
<Spinner
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/spinner2"
android:visibility="visible"
android:background="@drawable/rounded_corners"
android:layout_marginRight="5dp"
android:popupBackground="#FFB74D"
android:textAlignment="center"
android:gravity="center|top"
android:layout_weight="0.5"
android:layout_gravity="center" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/spinner3"
android:visibility="visible"
android:layout_marginLeft="5dp"
android:background="@drawable/rounded_corners"
android:popupBackground="#FFB74D"
android:textAlignment="center"
android:gravity="center|top"
android:layout_weight="0.5"
android:layout_gravity="center" />
</LinearLayout>
</RelativeLayout>
And the rounded_corners
file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFB74D"/>
<stroke android:width="0dip" android:color="#B1BCBE" />
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
</shape>