Java 带有数字的文本在RTL模式下是无序的(Android)
在RTL模式下,像“20分钟之前”这样的文本将是“20分钟之前” 我觉得这个系统将数字作为阿拉伯单词,因此在文本的右边强制20Java 带有数字的文本在RTL模式下是无序的(Android),java,android,right-to-left,Java,Android,Right To Left,在RTL模式下,像“20分钟之前”这样的文本将是“20分钟之前” 我觉得这个系统将数字作为阿拉伯单词,因此在文本的右边强制20 <TextView android:id="@+id/Mytext" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="end|right|center_vert
<TextView
android:id="@+id/Mytext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="end|right|center_vertical"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="5 minutes before"
android:textDirection="locale"/>
应为原始字符串“20分钟之前”。请检查下面的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/Mytext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="20 minutes before"
/>
</LinearLayout>
试试这个
<TextView
android:id="@+id/Mytext"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="start"
android:textAlignment="viewStart"
android:paddingLeft="4dp"
android:paddingStart="4dp"
android:text="5 minutes before"/>
LTR的输出
5分钟前
RTL的输出
5分钟前
用这个,
android:textAlignment="viewStart"
如果删除“android:textDirection=“locale”,则可以看到所需内容。我不知道你想让“5分钟前”显示哪个方向。如果左侧处于RTL和LTL模式,则可以根据以下内容设置“android:gravity=“开始|中心|垂直”,如果右侧处于“android:gravity=“结束|中心|垂直”:
android:supportsRtl
声明应用程序是否愿意从右向左支持
(RTL)布局。如果设置为true且targetSdkVersion设置为17或
更高的是,系统将激活并使用各种RTL API,以便
您的应用程序可以显示RTL布局。如果设置为false或
targetSdkVersion设置为16或更低,RTL API将被忽略
或者将没有任何效果,而您的应用程序将以相同的方式运行
与用户的区域设置选择关联的布局方向(您的
布局将始终从左到右)
所以,如果这是您想要实现的,而不是简单地在清单中设置
android:supportsRtl=false
。很抱歉让它变得不清楚,我希望它是“5分钟之前”,即使是在RTL中,我发现这种混乱的根本原因是当系统读取类似“5分钟之前”的字符串时“它将考虑基于第一字符的方向,在这种情况下,是5。5是英语和阿拉伯语,系统会以某种方式将其视为阿拉伯语,并导致此错误。为了避免这种情况,只需添加UniCode U+2068以跳过前导数字,一切都会很好。当系统语言为RTL语言(如阿拉伯语等)时,将文本方向强制为LTR,这将导致出现错误。删除LTR,它对英语和阿拉伯语都适用。我编辑我的答案。请尝试。查看它是否有帮助您可以在下面的链接中找到解决方案实际上,最好使用android:textDirection=“ltr”
明确标记此文本字段,至少在文本未翻译为阿拉伯语的情况下如此。