Android 4.2以下如何将layoutDirection设置为RTL

Android 4.2以下如何将layoutDirection设置为RTL,android,android-layout,Android,Android Layout,正在尝试将布局元素设置为RTL顺序 在4.2和更高版本中:layoutDirection=“rtl”和清单中:android:supportsRtl=“true”工作正常 但对于低于4.2的情况,则不是这样 有人解决吗?您将无法解决。它是在API级别17(4.2)中添加的,因此旧版本不支持它 只需使用android.support.v4.view就可以了 ViewCompat.setLayoutDirection(findViewById(R.id.my_view), ViewCompat.LA

正在尝试将布局元素设置为RTL顺序

在4.2和更高版本中:
layoutDirection=“rtl”
和清单中:
android:supportsRtl=“true”
工作正常

但对于低于4.2的情况,则不是这样


有人解决吗?

您将无法解决。它是在API级别17(4.2)中添加的,因此旧版本不支持它

只需使用android.support.v4.view就可以了

ViewCompat.setLayoutDirection(findViewById(R.id.my_view), ViewCompat.LAYOUT_DIRECTION_RTL);

您可以更改应用程序语言并解决此问题:

String languageToLoad  = "en";
Locale locale = new Locale(languageToLoad);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config,
getBaseContext().getResources().getDisplayMetrics());

所以你建议我改变xml中元素的顺序?这可能是为特定android API级别创建布局文件的最佳方法。e、 g.
layout-v17
以便新的API使用RTL布局,然后为旧版本创建一个布局,其中包含您需要的XML。您能找到解决方案吗?请检查答案,pleaseMagic!!伟大的解决方案@ArefBahreini此方法适用于api 17及以上。检查此方法的内部-if(VERSION.SDK_INT>=17){view.setLayoutDirection(layoutDirection);}