Android RTL文字方向

Ers*_*man 5 android right-to-left

我试图在我的应用程序中支持RTL语言环境,但是遇到了以下问题。现在我说问题,但是由于我对RTL语言环境不熟悉,这甚至可能不是问题,所以这里就解决了。

以下是3个文本视图。注意,以下输出是通过dev选项强制启用RTL的。

英文测试LTR

在此处输入图片说明

强制使用英语进行RTL测试

在此处输入图片说明

我感到奇怪的是,即使我说它android:gravity="start"如何与padding和margin等一起工作,它也没有正确地对齐,所以我查看了其他答案并发现了它android:textDirection="locale"

使用文本方向区域设置强制进行英语RTL测试

在此处输入图片说明

现在,这在LTR和RTL上均正确镜像,但是随后我注意到标点符号具有以下行为。不管这是否正确,这都引起了人们的关注,因为我正在与强制使用RTL的Google Play商店,Facebook和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>
Run Code Online (Sandbox Code Playgroud)

其他代码

我的清单文件中设置了以下内容

 android:supportsRtl="true"
Run Code Online (Sandbox Code Playgroud)

这是我的琴弦

<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>
Run Code Online (Sandbox Code Playgroud)

请原谅这听起来多么幼稚,并启发我!我希望提供舒适的RTL支持!

ʍѳђ*_*ઽ૯ท 7

添加android:textDirection="locale"TextViewandroid:supportsRtl="true"将达到目的。但是,textDirection="locale"为了更改语言环境,将方向更改为enfaar。(取决于设备的语言

足够清楚的是,它正常工作是因为您在TextViewis中LTR使用的文本以及您所使用的RTL方向,正如您所看到的那样,它确定了方向,RTL并且没有任何问题。另外,使用android:gravity="start"可能会迫使它从我假设的开始使用,它将从开始LTR。(我建议删除android:gravity="start"并让Android(以设备的语言为准)确定哪个最好)

因此,要测试其是否有效,可以将文本设置为阿拉伯语或波斯语,如下所示:

android:text="??? ?? ??? ???"
Run Code Online (Sandbox Code Playgroud)

如果它从RTL和开始"???",那么它将按预期工作。