我试图在我的应用程序中支持RTL语言环境,但是我遇到了以下问题。现在我说的是问题,但由于我对RTL语言环境的不熟悉,它甚至可能不是问题,所以这里就是这个问题。
下面是3个文本视图。注意:以下输出是通过dev选项在RTL强制打开的情况下产生的。
英语轻量级中的测试
英语实时习得强制中的测试
我发现奇怪的是,它没有向右对齐,尽管我说的是android:gravity="start"
,喜欢它与填充和边距等的工作方式,所以我查看了其他答案,发现了android:textDirection="locale"
。
使用文本方向语言环境强制进行英语即时教学中的测试
现在,这在LTR和RTL上都是正确的,但随后我注意到标点符号的以下行为。无论这是否正确,这都引起了人们的注意,因为我在与Google Play Store,Facebook和带有RTL forced的Whats App进行比较,当我查看带有标点符号的段落时,我没有看到这一点,这让我认为我做错了什么。
完整布局代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:text="@string/test_one"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="start"
android:text="@string/test_two"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="start"
android:text="@string/test_three"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
</LinearLayout>
其他代码
下面是在我的清单文件中设置的
android:supportsRtl="true"
这是我的弦
<string name="test_one">Good Job. You did well!</string>
<string name="test_two">3 hours ago</string>
<string name="test_three">Select Option:</string>
请原谅这听起来是多么天真,并启发我!我希望提供舒适的RTL支持!
发布于 2018-09-27 03:39:24
在TextView
和android:supportsRtl="true"
中添加android:textDirection="locale"
就可以了。但是,textDirection="locale"
会将方向更改为区域设置,即en
或fa
,或者是ar
。(取决于设备的语言)
要清楚的是,它工作正常,因为你在TextView
中的文本是LTR
的,并且你使用了RTL
方向,正如你所看到的,方向是RTL
,这是没有问题的。此外,使用android:gravity="start"
可能会强制它从start开始使用,我想它将从LTR
开始。(我建议删除android:gravity="start"
,让安卓(为了设备的语言)决定哪一个是最好的)
因此,要测试它是否正常工作,可以将文本设置为阿拉伯语或波斯语,如下所示:
android:text="این یک تست است"
如果它是从RTL
和"این"
开始的,那么它就会像预期的那样工作。
https://stackoverflow.com/questions/52524844
复制相似问题