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.

bigstones
  • 14,587
  • 6
  • 63
  • 80
Butters
  • 221
  • 2
  • 4

7 Answers7

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.

Macarse
  • 87,001
  • 42
  • 169
  • 229
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.

hackbod
  • 88,517
  • 16
  • 135
  • 152
1

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

Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194
ykay
  • 183
  • 1
  • 3
  • 7
0

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

textView.setText("\u200F"+content);
android developer
  • 106,412
  • 122
  • 641
  • 1,128
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!

dangalg
  • 5,949
  • 4
  • 24
  • 34
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

Igor Filippov
  • 14,641
  • 17
  • 81
  • 155
-1

I think this is what you're looking for:

android:layout_gravity="right"
MobileCushion
  • 6,816
  • 5
  • 37
  • 61
  • 2
    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. – Ted Hopp May 10 '11 at 15:32