question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

android:gravity="start" not working on TextViews on RTL locales

See original GitHub issue

It seems the lib is making TextViews to ignore (or have inverted) the setting android:gravity=“end/start” when RTL is used (by choosing hebrew as the device language for example).

If you set the device in Hebrew and have a TextView:

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="start" 
    android:text="hello world" />

Current result: the text appears aligned to the left (which is wrong) because the devices is currently RTL.

Expected result: the text should appear aligned to the right.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

81reactions
guangyyacommented, Apr 13, 2021

I have met the same issue, though I did not use this library…

I googled why I met this issue, and luckily I found a solution.

Add

                android:textDirection="locale"
                android:textAlignment="viewStart"

rather than android:gravity="start"

And it does work.

1reaction
apkellycommented, Mar 20, 2017

@richardjbs This will still show the text on the left because you have hard-coded a western character set. If you use a reference to @string/hello_world and replace that in strings.xml for both values-en and values-iw (for hebrew) it should work as expected.

I’m working on a project which supports Arabic and English and have seen this many times. I don’t believe Calligraphy is related to this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

use locale (ltr/rtl) for gravity in TextView - android
The obvious choice would be: android:gravity="start" but then e.g. english text will always be left-aligned and hebrew right-aligned.
Read more >
Android – use locale (ltr/rtl) for gravity in TextView - iTecNote
The obvious choice would be: android:gravity="start" but then e.g. english text will always be left-aligned and hebrew right-aligned. Here is how it looks...
Read more >
Support different languages and cultures - Android Developers
Some users choose a language that uses right-to-left (RTL) scripts, such as Arabic or Hebrew, for their UI locale.
Read more >
Supporting RTL Design on Android - droidcon
Otherwise, your app will not support the RTL design. ... meaning “layout direction right-to-left” for resources working on RTL languages.
Read more >
Dos and Don'ts for Developing Multilingual Android Apps
It also provides mechanisms for locale awareness, resource loading, ... and you don't add the resConfigs property, it will not work properly, and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found