Android: align text to the right, but not in the center

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

I used the same approach mentioned by Android here - the text is shifted left in Spinner , but I set gravity to the 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 that

 adapter.setDropDownViewResource(R.layout.spinner_item); 

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

English spinner

But currently it looks like this:

Arabic spinner

How to restore the following:

  • Radio button
  • Larger text size
  • I want this to be on the right, as shown, but centered between the two delimiters.

NOTE. Arabic web services are not finished yet, so the data in the image is still in English.

UPDATE

After you asked Adil Soomro, I get the following:

Spinner semi-desired

There is no rocket, and there is considerable space between the border and the first letter.

UPDATE

After editing Adil Soomro, I now have the following:

Spinner Arabic Fixed

+6
source share
3 answers

You must use CheckedTextView , it will solve all your problems.

You put the xml layout 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" /> 
+6
source

Try the following:

 android:layout_gravity="right" 
+1
source

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" /> 

For

 <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" /> 
0
source

Source: https://habr.com/ru/post/919736/


All Articles