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,
But it currently looks like this,
How can I restore the following:
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,
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,
To right align text in TextView in Kotlin Android, set android:textAlignment attribute with the value “viewEnd” in layout file, or programmatically set the textAlignment property of the TextView object with View.
android:gravity="center" for text center in TextView. android:gravity="center_horizontal" inner text if you want horizontally centered. android:gravity="center_vertical" inner text if you want vertically centered. android:layout_centerInParent="true" if you want TextView in center position of parent view.
Kotlin Android – Center Align text in TextView To center align text in TextView in Kotlin Android, set android:textAlignment attribute with the value “center” in layout file, or programmatically set the textAlignment property of the TextView object with View. TEXT_ALIGNMENT_CENTER in activity file.
Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one.
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" />
Try this:
android:layout_gravity="right"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With