Home » Android » android – TextView gravity not working with Hebrew

android – TextView gravity not working with Hebrew

Posted by: admin May 14, 2020 Leave a comment


I have TextView on Hebrew that i want to be on the right side, so i’m doing


On some phones it will be aligned to right and on some it will be aligned to left.
I think it depends on some phone configuration.
How i can fix it ??


How to&Answers:

This might be an issue. If it’s not in the Android’s issue page consider reporting it.

For now you can try fixing it placing the TextView inside a ViewGroup.
Use wrap_content and layout_gravity to place it correctly inside it’s parent.


Android currently doesn’t support BiDi text. Some manufacturers have hacked it in, but until this is a standard part of the platform you can expect any use of BiDi text to result in inconsistent, broken behavior. Sorry.


Android: Gravity might not work properly in case android:layout_height or android:layout_weight is set to wrap_content.


I’ve found the solution. If your text is in hebrew, you don’t need to set gravity, because it would be aligned without it. I came to this when I saw latin symbols in my views, which were on the right. Though, there is still bug in SDK layout editor.

Tested on LG GT540 and Samsung Galaxy S


if you wish the text to be aligned to the right , try using this:



This is happening because the older android versions don’t support rtl too well.
For me what worked eventually was a webview.
Because then I just used CSS to design my text.
You will also need an onTouchListener if you want it to do something when clicked

change your TextView to Webview:

        android:layout_height="wrap_content" />

My code:

WebView webView = (WebView) findViewById(R.id.noticetit);
private void setWebView() {
            String htmlcss = "<html lang=\"he\"><head><meta charset=\"utf-8\" />"
                    + "<style type=\"text/css\">.rtl {direction: rtl;color:black;font:20px arial;}</style></head>"
                    + "<body class=\"rtl\"><div class=\"rtl\">" + webView
                    + "</div></body></html>";

            webView.loadDataWithBaseURL(null, htmlcss, "text/html", "utf-8", null);
            webView.setOnTouchListener(new OnTouchListener() {
                // Removed @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (v.getId() == R.id.maintitle
                            && event.getAction() == MotionEvent.ACTION_DOWN) {
                        //Put your code here
                    return false;

Hope this helps you out!


I think this is what you’re looking for: