Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid:gravity="right" not working on all devices for Arabic and other RTL languages
    primarykey
    data
    text
    <p>I've got an Arabic Android application, and here is the XML code:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/greygradientbackground"&gt; &lt;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" /&gt; &lt;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"/&gt; &lt;/RelativeLayout&gt; </code></pre> <p>The problem is that android:gravity works on some Android models and on others don't.</p> <p>To be more specific, I've tested the app on many 2.3.3 android devices and the Arabic text is aligned right. However on other 2.3.3 devices the Arabic text is aligned left (which is wrong).</p> <p>When I changed android:gravity="right" to android:gravity="left" the problem shifted from the second group of devices to the first.</p> <p>So my question is how can I solve this issue especially that as far as I know there aren't a way to localize layouts based on a device model number.</p> <p>Thanks in advance for any guidance because am totally lost. :(</p> <p><strong>UPDATE:</strong></p> <p>I searched about "How to align Arabic correctly on all Android versions?" but found nothing working on all my testing devices. Any suggestions please? I am sure there is a best practice approach for aligning Arabic text on Android.</p> <p><strong>UPDATE 2:</strong></p> <p>I tried to use a WebView instead of a TextView to align Arabic correctly using CSS styles. However, the Arabic text is showing in the WebView as strange characters.</p> <p>Here is the Code:</p> <pre><code>mWebView.loadData("&lt;html dir=\"rtl\"&gt;الأسم&lt;body&gt;&lt;/body&gt;&lt;/html&gt;", "text/html", "UTF-8"); </code></pre> <p>The strange thing is that Arabic websites text is displayed correctly. So, what's the problem? :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload