每当我应用 layoutAmount.setRotationY(180);
时,我正在动态地创建和添加线性布局中的 TextViews也会改变错误的方向,例如,如果单词 sorry its 变成 yrros,我该如何正确应用 RTL
谢谢!
最佳答案
setLayoutDirection 会根据语言设置布局方向
-确保使用布局重力开始和结束
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());
}
关于java - 如何动态有效地应用 RTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983285/