1

在将语言从英语切换到阿拉伯语时,布局从左到右变化。如何从左到右更改 textView。示例(英文)Ramesh 以 34 公里/小时的速度驾驶。(阿拉伯语) hpmk43 fo deeps a htiw gnivird hsemaR

编辑1:请找出下面的图片是否正确?

阿拉伯语版本 英文版

4

3 回答 3

1

setLocale("en");//设置英文

setLocale("ar");//设置阿拉伯语

public void setLocale(String lang) {
        Locale locale = new Locale(lang);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config,
                getBaseContext().getResources().getDisplayMetrics());
    }

将语言环境设置为英语和 LTR 将语言环境设置为阿拉伯语后将自动 RTL。//不要忘记重新启动您的应用程序。设置语言环境后

无需改变重力

于 2017-01-07T07:06:51.377 回答
1

TextView为 RTL 工作,您应该添加 RTL 的布局属性。

使用android:layout_marginStart代替android:layout_marginLeftandroid:layout_marginEnd代替android:layout_marginRight

对于left-to-right流量,start=leftend=right

对于right-to-left流量,start=rightend=left

这种 RTL 支持是在 API 级别 17 中添加的,作为 Android 4.2 对 RTL 布局的支持的一部分。这将对您有所帮助 https://developer.android.com/about/versions/android-4.2.html#RTL

于 2017-01-09T05:02:11.817 回答
0

将您应用的所有left/right布局属性更改为新的start/end等效项。

简单的例子,使用 in android:gravity

不要忘记在您的应用中声明Manifest您的应用支持 RTL 镜像:添加android:supportsRtl="true"Manifest文件中的元素。

于 2017-01-07T06:54:45.870 回答