Android: Spinner text alignment to the right but n

2019-02-09 21:00发布

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.

I used the same approach mentioned here Android - Text is Pushed to the Left in a Spinner but I set the gravity to right.

Here is my spinner_item.xml

<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:gravity="right" />

Changed my code from

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

to this

adapter.setDropDownViewResource(R.layout.spinner_item);

I want my spinner to look like my old English spinner found below,

English spinner

But it currently looks like this,

Arabic spinner

How can I restore the following:

  1. The radio button
  2. The bigger text size
  3. I want it to the right as shown but centered between the two dividers.

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

UPDATE

After trying Adil Soomro's suggestion, I get the following,

Spinner semi-desired

There is no radiobutton and there is a considerable space between the border and the first letter.

UPDATE

After Adil Soomro's edit, I now have the following,

Spinner Arabic Fixed

3条回答
狗以群分
2楼-- · 2019-02-09 21:02

change your code

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:layout_width="fill_parent"
    android:gravity="right" />

To

<TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        style="?android:attr/listPreferredItemHeight"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right" />
查看更多
我只想做你的唯一
3楼-- · 2019-02-09 21:03

Try this:

android:layout_gravity="right"
查看更多
beautiful°
4楼-- · 2019-02-09 21:08

You have to use CheckedTextView, it will solve your all 3 problems.

You will place a layout xml something like this:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
    android:gravity="right|center_vertical"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:textSize="20dp"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee" />
查看更多
登录 后发表回答