android:gravity="start" in RTL aligns the text to left not right
Asked Answered
P

2

9

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>
Pammie answered 3/5, 2016 at 5:44 Comment(7)
what version you targeting ? post your build.gradleFaubert
what do you mean by I didn't depend on it.Loganloganberry
@NJ targeting API 15Pammie
I mean I don't want to use it as you see I'm targeting API 15 not 17Pammie
@Pammie did you solved your problem for api 17 and above, in fact I'm facing the same, when characters are arabic the text respects the gravity start but when the texts are a-zA-Z it doesn't.Haemachrome
You can either disable the RTL by setting android:layoutDirection="ltr" in the layout file .. or another workaround by inserting an empty view like I said in the last answer here.Pammie
Is this a known bug? It's happening to me with minSdkVersion 18Haga
F
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

Faubert answered 3/5, 2016 at 5:54 Comment(2)
Great to know that. Still I don't understand why "gravity" does not work properly even on a device running android 4.4.4 ?Pammie
have you set android:supportsRtl="true" to the <application> element in your manifest file.Faubert
P
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"

Pammie answered 3/5, 2016 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.