I'm trying to set attributes to a spinner on my android app and one of the attributes in textAlignment = "right"
(the problem being I've a spinner that layout_width="match_parent"
so there's a lot a space and I'd like to have it to the right) but this is only supported in API 17 and up whereas I want to make an app for API 16 - Is there a work-around?
My attributes are:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textAlignment="gravity"
android:id="@+id/MainSpinner"
tools:listitem="@layout/support_simple_spinner_dropdown_item"/>
The current linearLayout looks like this:
And I want it to look like this:
Where:
LinearLayout (horizontal) =
RelativeLayout =
TextView =
LinearLayout (Vertical) =
Spinner =
Button =
This ans work for me...
<Spinner
android:id="@+id/example_spinner"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:textAlignment="right"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="2dp"
android:paddingBottom="2dp" />
I've followed this : http://nevescheng.blogspot.fr/2013/05/spinner-with-item-text-aligned-to-center.html & this worked fine...
You can create an adapter like this :
SpinnerAdapter spinnerAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, new String[]{"tata", "toto", "titi"});
spriner.setAdapter(spinnerAdapter );
and in your layout (res/layout/spinner_item.xml
):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical|end"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeightSmall" />
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