如何动态有效地应用RTL [英] How to apply RTL dynamically and effectively

查看:54
本文介绍了如何动态有效地应用RTL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我应用 layoutAmount.setRotationY(180); 时,我都会动态地在线性布局中创建和添加TextViews,布局会更改其方向,但正确的是TextViews的单词也改变了方向,例如,如果单词对不起,它变成了yrros,我该如何正确应用RTL

I'm creating and adding TextViews in linear layout dynamically, whenever I'm applying layoutAmount.setRotationY(180); the layout changes its direction which is right, but the words of TextViews inside it also changes direction which is wrong, for example, if the word is sorry its becomes yrros, how can I apply RTL correctly

谢谢!

推荐答案

setLayoutDirection 将根据语言设置布局方向

setLayoutDirection will set layout direction according to the language

-确保使用布局重力起点和终点

-Make sure that use layout gravity start and end

 public static void setLanguage(Context context, String language) {
            String[] localeLang = language.split("_");
            Locale locale;
            if (localeLang.length > 1)
                locale = new Locale(localeLang[0], localeLang[1]);
            else
                locale = new Locale(localeLang[0]);
            Locale.setDefault(locale);
            Configuration config = new Configuration();
            config.locale = locale;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                config.setLayoutDirection(locale);
                ((Activity) context).getWindow().getDecorView().setLayoutDirection(config.getLayoutDirection());
            }
            context.getResources().updateConfiguration(config,
                    context.getResources().getDisplayMetrics());
        }

这篇关于如何动态有效地应用RTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆