Align spinner values to right instead of left
Asked Answered
G

3

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.

Goose answered 17/5, 2012 at 4:18 Comment(0)
C
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);
Crossroads answered 17/5, 2012 at 4:35 Comment(4)
10x. but now how I can load to this spinner/textView the array of values?Goose
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.Goose
Here is how you should go to make it custom spinner itemCrossroads
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 ...Placet
H
15

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

Hitchhike answered 2/12, 2016 at 1:36 Comment(1)
You must also specify gravity or layout_gravity="end"Mima
S
1

You can try with spinner item text alignment right end :

view.textAlignment = View.TEXT_ALIGNMENT_TEXT_END
Scut answered 19/7, 2021 at 6:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.