4

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);
Nouran H
  • 1,992
  • 5
  • 18
  • 24

2 Answers2

11

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

Community
  • 1
  • 1
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
0

All you need to do is create a new spinner dropdown layout and set android:gravity="right" on the appropriate widget.

Call it with:

yourSpinner.setDropDownViewResource(R.layout.right_aligned_spinner_dropdown_item); 
Barak
  • 16,318
  • 9
  • 52
  • 84
  • Thank you for your answer. If you could please check my other post http://stackoverflow.com/questions/11341613/android-spinner-text-alignment-to-the-right-but-not-centered you will see that I am using android:gravity="right|center_vertical" but it's only being applied to the drop down view and not the unclicked spinner view. Any ideas? – Nouran H Jul 05 '12 at 13:13