I have an Android app in Arabic and here is the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/greygradientbackground"> <ImageView android:id="@+id/logo" android:layout_width="150dp" android:layout_height="fill_parent" android:scaleType="centerCrop" android:layout_margin="5dp" android:layout_alignParentTop="true" android:layout_alignParentRight="true" /> <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="#000000" android:layout_gravity="center_vertical|right" android:gravity="right" android:layout_toLeftOf="@id/logo"/> </RelativeLayout>
The problem is that android: gravity works on some Android models, but not on others.
To be more specific, I tested the application on many 2.3.3 Android devices, and the Arabic text is aligned to the right. However, on other 2.3.3 devices, Arabic text is aligned to the left (which is incorrect).
When I changed android: gravity = "right" to android: gravity = "left" the problem moved from the second group of devices to the first.
So my question is, how can I solve this problem, especially since, as far as I know, there is no way to localize layouts based on the model number of the device.
Thanks in advance for any guidance because I totally lost. :(
UPDATE:
I searched about "How to properly align the Arabic language on all versions of Android?" but nothing works on all my test devices. Any suggestions please? I'm sure there is an optimal approach for aligning Arabic text on Android.
UPDATE 2:
I tried using WebView instead of TextView to properly align the Arabic language using CSS styles. However, Arabic text appears as strange characters in WebView.
Here is the code:
mWebView.loadData("<html dir=\"rtl\">Ψ§ΩΨ£Ψ³Ω
<body></body></html>", "text/html", "UTF-8");
It is strange that the text of the Arabic websites is displayed correctly. So what is the problem ?: (