TextView gravity not working with Hebrew
Asked Answered
B

7

11

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

<TextView....
    android:gravity="right"
</TextView>

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 ??

Thanks.

Beutner answered 5/4, 2011 at 19:41 Comment(0)
O
3

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.

Organization answered 27/6, 2011 at 13:20 Comment(0)
T
1

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.

Tapp answered 1/7, 2011 at 0:52 Comment(1)
Is there a flag to tell if a certain manufacture has hacked this in?Catarinacatarrh
M
1

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

Marcelo answered 11/12, 2011 at 17:16 Comment(0)
S
0

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

Shiloh answered 2/7, 2011 at 13:24 Comment(0)
T
0

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

textView.setText("\u200F"+content);
Thistle answered 16/8, 2012 at 23:41 Comment(0)
C
0

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:

<WebView
        android:id="@+id/noticetit"
        android:layout_width="wrap_content"
        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!

Chiseler answered 27/3, 2014 at 19:53 Comment(0)
E
-1

I think this is what you're looking for:

android:layout_gravity="right"
Eulogy answered 5/4, 2011 at 19:51 Comment(1)
This is not what OP is looking for. android:layout_gravity suggests where a view should be placed within its parent. android:gravity is supposed to control how a TextView aligns its text when the text is narrower or shorter than the view.Horsepowerhour

© 2022 - 2024 — McMap. All rights reserved.