android:是约束布局支持RTL

man*_*pha 13 android right-to-left

什么是在Android Studio的约束布局中支持RTL的最佳实践,
或者我应该创建一个分隔布局,一个用于英语,另一个用于阿拉伯语?

英文版

英文版

预期的布局与阿拉伯语 预期的布局与阿拉伯语

将设备语言从英语更改为阿拉伯语时的输出布局 将语言从英语更改为阿拉伯语时的输出布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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">

    <TextView
        android:text="@string/CourseName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView7"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="16dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1" />

    <Button
        android:text="@string/enroll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_marginTop="16dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginEnd="16dp"
        app:layout_constraintRight_toRightOf="parent"
        android:layout_marginRight="16dp"
        android:textAppearance="@style/TextAppearance.AppCompat.Display2" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

Mar*_*ini 11

正如CommonsWare已经指出的那样,如果你计划支持RTL语言,你应该很少/从不使用Left/Right,特别是如果你的目标是API 16+.

更换你app:layout_constraintRight_toRightOf="parent"app:layout_constraintEnd_toEndOf="parent"等等.

右为止,左为止.


Mey*_*ann 6

不幸的是,他们做得不对(或"结束";-)).

在许多约束中,例如对父对象的约束,Android Studio使用"Left"/"Right"创建约束,其中它应分别使用"Start"/"End".它导致RTL语言出现问题(其字母表为中东的每种语言).

更糟糕的是:我甚至没有看到任何关于此的漏洞.

我的解决方案:关闭Android Studio (因此它不会在我编辑时跳转并尝试修复),然后,使用Atom和RegExp(或sed命令),我小心地将" layout_constraintLeft_toLeftOf" 替换为" layout_constraintStart_toStartOf"和" layout_constraintRight_toRightOf"改为" layout_constraintEnd_toEndOf" .

对不起,没有找到任何不那么傻的东西:-(

注意 链接更糟糕.RTL布局甚至不能很好地链接,也不保持布局.

在这种情况下,我的结论是回到旧的Layouts,直到Google为RTL语言提供成熟的支持...... 毕竟,RTL早在LTR之前就已存在;-)

更新:解决方案即将来临

我向Google开了一个错误.他们说它将"固定在2.4".

更新:


在2.4中标记为固定固定

在2017年4月25日