【问题标题】:TextView gravity not working with HebrewTextView 重力不适用于希伯来语
【发布时间】:2011-07-30 06:37:52
【问题描述】:

我有希伯来语的 TextView,我想放在右边,所以我在做

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

在某些手机上,它会向右对齐,而在某些手机上,它会向左对齐。 我认为这取决于某些手机配置。 我该如何解决它??

谢谢。

【问题讨论】:

    标签: android textview hebrew gravity


    【解决方案1】:

    发生这种情况是因为较旧的 android 版本不太支持 rtl。 对我来说,最终起作用的是 webview。 因为那时我只是使用 CSS 来设计我的文本。 如果您希望它在单击时执行某些操作,您还需要一个 onTouchListener

    将您的 TextView 更改为 Webview:

    <WebView
            android:id="@+id/noticetit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    

    我的代码:

    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;
                    }
                });
            }
    

    希望对你有所帮助!

    【讨论】:

      【解决方案2】:

      如果您希望文本向右对齐,请尝试使用:

      textView.setText("\u200F"+content);
      

      【讨论】:

        【解决方案3】:

        如果android:layout_heightandroid:layout_weight 设置为wrap_contentAndroid: Gravity 可能无法正常工作。

        【讨论】:

          【解决方案4】:

          我找到了解决方案。如果您的文本是希伯来语,则不需要设置重力,因为没有它就会对齐。当我在我的视图中看到拉丁符号时,我想到了这一点,它们在右边。不过,SDK 布局编辑器中仍然存在错误。

          在 LG GT540 和三星 Galaxy S 上测试

          【讨论】:

            【解决方案5】:

            Android 目前不支持双向文本。一些制造商已经入侵了它,但在这成为平台的标准部分之前,您可以预期任何使用 BiDi 文本都会导致不一致、损坏的行为。对不起。

            【讨论】:

            • 是否有标志表明某个制造商是否入侵了它?
            【解决方案6】:

            这可能是个问题。如果它不在 Android 的 issue page 中,请考虑报告它。

            现在您可以尝试将TextView 放置在ViewGroup 中来修复它。 使用 wrap_contentlayout_gravity 将其正确放置在其父级中。

            【讨论】:

              【解决方案7】:

              我想这就是你要找的东西:

              android:layout_gravity="right"
              

              【讨论】:

              • 不是 OP 正在寻找的。 android:layout_gravity 建议视图应放置在其父级中的哪个位置。 android:gravity 应该控制 TextView 在文本比视图窄或短时如何对齐其文本。
              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-09-12
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多