2

Text like "20 minutes before" will be "minutes before 20" in RTL mode.

I feel like the system takes number as Arabic word, thus force 20 to the very right of the text.

<TextView
    android:id="@+id/Mytext"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="end|right|center_vertical"
    android:paddingLeft="4dp"
    android:paddingStart="4dp"
    android:text="5 minutes before"
    android:textDirection="locale"/>

Original string "20 minutes before" is expected.

Chris Liu
  • 21
  • 3

5 Answers5

2

if you delete "android:textDirection="locale"", then you can see what you want. i don't know which direction you want the "5 minutes before" showing. if left in RTL and LTL mode, you can set " android:gravity="start|center_vertical"", else if right "android:gravity="end|center_vertical"

justYuMu
  • 69
  • 3
  • Actually, it's probably better to explicitly mark this text field with `android:textDirection="ltr"`, at least as long as the text is not translated to Arabic. – Alex Cohn Sep 11 '19 at 14:51
1

use this,

android:textAlignment="viewStart"
George Z.
  • 6,643
  • 4
  • 27
  • 47
Ronak Ukani
  • 603
  • 5
  • 20
0

Please check below code

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    >
    <TextView
        android:id="@+id/Mytext"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:paddingLeft="4dp"
        android:paddingStart="4dp"
        android:text="20 minutes before"

        />
</LinearLayout>
Emad Seliem
  • 608
  • 1
  • 4
  • 5
0

Try this

<TextView
        android:id="@+id/Mytext"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="start"
        android:textAlignment="viewStart"
        android:paddingLeft="4dp"
        android:paddingStart="4dp"
        android:text="5 minutes before"/>

Output for LTR

5 minutes before

Output for RTL

before minutes 5

Rajnish suryavanshi
  • 3,168
  • 2
  • 17
  • 23
  • Sorry for making it unclear, i'd like it to be '5 minutes before' even in RTL, and I found out the root reason for this disorder is that when System reads a string like "5 minutes before", it will consider its direction based on first character, in this case, is 5. 5 is either English and Arabic, the system will take it as Arabic somehow and caused this bug. To avoid this, simply add UniCode U+2068 to skip leading numbers, everything is gonna be fine. http://unicode.org/reports/tr9/#Directional_Formatting_Characters – Chris Liu Sep 11 '19 at 09:18
0

According to:

https://developer.android.com/guide/topics/manifest/application-element.html#supportsrtl

android:supportsRtl

Declares whether your application is willing to support right-to-left (RTL) layouts. If set to true and targetSdkVersion is set to 17 or higher, various RTL APIs will be activated and used by the system so your app can display RTL layouts. If set to false or if targetSdkVersion is set to 16 or lower, the RTL APIs will be ignored or will have no effect and your app will behave the same regardless of the layout direction associated to the user's Locale choice (your layouts will always be left-to-right).

so, if this is what you want to achieve than simply set android:supportsRtl = false in Manifest.

Brainnovo
  • 1,749
  • 2
  • 12
  • 17