Android: Spinner selection aligned to the left

Nouran H picture Nouran H · Jul 5, 2012 · Viewed 8k times · Source

I finished the English version of my application and now I am working on the Arabic localization. Arabic is a right-to-left language, so I need to adjust a lot of things in my layout, including my spinner display.

When I choose an item from the spinner selection menu, I see the following,

Spinner selection

As you can see "Allergy" is aligned to the left and on top of the spinner arrow. I need it to be aligned to the right.

NOTE The Arabic webservices aren't finished yet, that's why the data in the image is still in English.

EDIT

Spinner mSpecialtySpinner = (Spinner) findViewById(R.id.specialty_appointment_spinner);
        ArrayAdapter<Specialty> adapter = new ArrayAdapter<Specialty>(AppointmentReservationActivity.this,android.R.layout.simple_spinner_item, specialities);
        adapter.setDropDownViewResource(R.layout.spinner_item);
        mSpecialtySpinner.setAdapter(adapter);

Answer

Adil Soomro picture Adil Soomro · Jul 5, 2012

Well you can have another layout for Spinner and pass it to ArrayAdapter's constructor.

make an xml file naming spinner_layout.xml in layout like this:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1" 
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:textSize="20sp"
    android:paddingLeft="6dip"
    android:paddingRight="6dip" 
    android:gravity="right"
     />

and now pass it in ArrayAdapter's constructor like this:

new ArrayAdapter<String>(this,R.layout.spinner_layout,conversionsadd);

Please remember:

what we have provided as R.layout.spinner_layout in ArrayAdapter constructor is layout of Spinner. and what we will provide as setDropdownView() is Spinner item (drop down item).

You can have a look at my another relative answer here