David
David

Reputation: 37546

Align spinner values to right instead of left

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.

Upvotes: 16

Views: 26651

Answers (3)

Vishal_VE
Vishal_VE

Reputation: 2137

You can try with spinner item text alignment right end :

view.textAlignment = View.TEXT_ALIGNMENT_TEXT_END

Upvotes: 1

Eddy Charry
Eddy Charry

Reputation: 207

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

Upvotes: 15

Lalit Poptani
Lalit Poptani

Reputation: 67286

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);

Upvotes: 21

Related Questions