16

In spinner xml, I'm using:

 android:entries="@array/cars"

where cars is list of numeric items.

The spinner automatically align values to left, and I can't find in xml/code how to change it.

David
  • 37,109
  • 32
  • 120
  • 141

3 Answers3

21

You have to use a custom view here to give alignment to the Spinner values. Create a CustomView like this answer has created and add android:gravity to the TextView as right.

UPDATE:

Set the CustomView to your adapter using

adapter.setDropDownViewResource(android.R.layout.your_custom_created_view);
Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
  • 10x. but now how I can load to this spinner/textView the array of values? – David May 17 '12 at 05:03
  • 1
    10x again. I can add adapter to my code, but I can't set my custom view to this adapter because it's now "TextView" and not a Spinner. – David May 17 '12 at 05:33
  • [Here is how you should go to make it custom spinner item](http://www.android10.org/index.php/forums/43-view-layout-a-resource/924-tutorial-custom-spinner-with-icon) – Lalit Poptani May 17 '12 at 05:37
  • 3
    As of now, alignment of the selected item of a spinner can be changed by `android:gravity="right"` directly. I'm not sure when they changed this ... – Dominikus K. Mar 31 '16 at 13:11
15

You can use TextAlignment on properties and select TextEnd, or android:textAlignment="textEnd" on XML simple

Tushar
  • 85,780
  • 21
  • 159
  • 179
Eddy Charry
  • 207
  • 2
  • 7
1

You can try with spinner item text alignment right end :

view.textAlignment = View.TEXT_ALIGNMENT_TEXT_END
Vishal_VE
  • 1,852
  • 1
  • 6
  • 9