我有希伯来语的 TextView 我想在右边,所以我在做
<TextView....
android:gravity="right"
</TextView>
在某些手机上,它会向右对齐,而在某些手机上,它会向左对齐。我认为这取决于某些手机配置。我该如何解决?
谢谢。
这可能是个问题。如果它不在 Android 的问题页面中,请考虑报告它。
现在,您可以尝试将其放置TextView
在ViewGroup
. 使用wrap_content
andlayout_gravity
将其正确放置在其父级中。
Android 目前不支持双向文本。一些制造商已经入侵了它,但在这成为平台的标准部分之前,您可以预期任何使用 BiDi 文本都会导致不一致、损坏的行为。对不起。
Android: Gravity
可能无法正常工作以防万一android:layout_height
或android:layout_weight
设置为wrap_content
.
我找到了解决方案。如果您的文本是希伯来语,则不需要设置重力,因为没有它就会对齐。当我在我的视图中看到拉丁符号时,我想到了这一点,它们在右边。不过,SDK 布局编辑器中仍然存在错误。
在 LG GT540 和三星 Galaxy S 上测试
如果您希望文本向右对齐,请尝试使用:
textView.setText("\u200F"+content);
发生这种情况是因为较旧的 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;
}
});
}
希望这可以帮助你!
我想这就是你要找的:
android:layout_gravity="right"