我正在尝试在我的应用程序中支持RTL语言环境但是我遇到了以下问题.现在我说问题,但由于我不熟悉RTL语言环境,它甚至可能不是问题,所以在这里.
以下是3个文本视图.请注意,已通过dev选项强制打开RTL,以下输出.
英语LTR考试
测试英语RTL强制
我发现很奇怪它没有对齐到右边,即使我说android:gravity =“start”就像它如何使用填充和边距等所以我看了其他答案并遇到了android:textDirection =“locale” .
使用文本方向区域设置强制执行英语RTL测试
现在这在LTR和RTL上都能正确镜像,但后来我注意到了标点符号的以下行为.这引起了人们的关注,不管这是否正确,因为我正在与谷歌Play商店,Facebook和Whats App进行比较,强迫使用RTL,当我看到带有标点符号的段落时,我没有看到这一点,这让我觉得我做错了什么.
完整布局代码
<?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支持!
解决方法:
将android:textDirection =“locale”添加到TextView和android:supportsRtl =“true”将成功.但是,textDirection =“locale”会改变方向,以便为en或fa或ar的语言环境. (取决于设备的语言)
并且要足够清楚,它正常工作,因为TextView中的文本是LTR并且您使用了RTL方向,正如您所看到的,它使方向RTL并没有问题.此外,使用android:gravity =“start”可能会强制它从开始使用,我想,它将从LTR开始. (我建议删除android:gravity =“start”并让Android(以设备的语言)决定哪一个是最好的)
因此,要测试它是否正常工作,您可以将文本设置为阿拉伯语或波斯语,如下所示:
android:text="این یک تست است"
如果它从RTL和“این”开始,那么它按预期工作.
标签:android,right-to-left 来源: https://codeday.me/bug/20190527/1161781.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。