7

While testing my layout on a device with RTL language (Arabic) I found that TextView with gravity:start keeps aligning the text to the left instead of right ! I tried android:textAlignment="viewStart" and it works correctly but due to API reqs I didn't depend on it.

my code (I mean the first textview in my code) :

<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
>

<TextView
    android:text="Size"
    android:gravity="start"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"/>

<LinearLayout android:gravity="center" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content">
    <TextView
        android:text="000"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="subtext"/>
</LinearLayout></LinearLayout>
Bialy
  • 779
  • 1
  • 11
  • 20

2 Answers2

3

For Full support or RTL you have to target api 17

If you are targeting your app to Android 4.2 (the app's targetSdkVersion or minSdkVersion is 17 or higher), then you should use “start” and “end” instead of “left” and “right”. For example

Native RTL support in Android 4.2

Community
  • 1
  • 1
N J
  • 25,967
  • 13
  • 73
  • 94
  • 1
    Great to know that. Still I don't understand why "gravity" does not work properly even on a device running android 4.4.4 ? – Bialy May 03 '16 at 05:58
  • 1
    have you set `android:supportsRtl="true"` to the ` ` element in your manifest file. – N J May 03 '16 at 06:17
1

My current workaround for this if any one is interested in the future is adding an empty view between the two elements and making it fill the empty space between them (weight = 1) so they get aligned properly. Still I don't understand that abnormal behavior of gravity="start"

Bialy
  • 779
  • 1
  • 11
  • 20