【问题标题】:Android below 4.2 how to set layoutDirection to be RTLAndroid 4.2以下如何设置layoutDirection为RTL
【发布时间】:2013-12-04 13:55:32
【问题描述】:

试图将布局元素设置为 RTL 排序

在 4.2 及以上行:layoutDirection="rtl" 和清单中:android:supportsRtl="true" 工作正常。

但对于低于 4.2 的则不是。

有人解决吗?

【问题讨论】:

  • 你能找到解决办法吗?
  • 请检查this的答案

标签: android android-layout


【解决方案1】:

只需使用 ViewCompat 使用 android.support.v4.view 即可。

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

【讨论】:

  • 魔法!!很好的解决方案!
  • @ArefBahreini 此方法适用于 api 17 及更高版本。检查此方法的内部 - if (VERSION.SDK_INT >= 17) { view.setLayoutDirection(layoutDirection); }
【解决方案2】:

你将无法做到。它是在 API Level 17 4.2 中添加的,因此旧版本不支持它。

【讨论】:

  • 所以你建议我改变 xml 中元素的顺序?
  • 可能是为特定 android API 级别创建布局文件的最佳方式。例如layout-v17 以便新 API 使用 RTL 布局,然后为旧版本创建一个布局,这些版本具有您需要的 XML 方式
【解决方案3】:

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

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());

【讨论】:

    猜你喜欢
    • 2019-08-09
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-19
    • 2021-05-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多