android - 为什么在 LinearLayout 上设置 LayoutDirection 不会立即生效?

标签 android

我正在使用 API 17 (4.2) 开发一个应用程序。在应用程序中我正在设计一个布局类,我想根据布局方向进行配置。但是,我没有成功检索类中应用的布局方向:

LinearLayout layout = newLayout(context);
layout.setLayoutDirection(LAYOUT_DIRECTION_RTL);
int ld = layout.getLayoutDirection();    // STILL 0! I was expecting 1

我的问题是,如何配置布局方向,并在类中检索它?

最佳答案

将此添加到您的 AndroidManifest.xml 中:

<application 
    ...
    android:supportsRtl="true"
    >

由于 View 首先检查 RTL 支持,如果为真,则解析布局方向。

您可以在 View.resolveLayoutDirection() 中获取更多详细信息。

关于android - 为什么在 LinearLayout 上设置 LayoutDirection 不会立即生效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27973572/

相关文章:

android - 将 Listview 移动到 View android 的底部

android - 如何在 android 中按住和拖动(重新定位)布局及其关联的布局

安卓 : AlarmManager fires off for past time

android - 按字符串查找可绘制对象

android - 使用 Retrofit 发布原始数据

带有服务定位器的 Android MVVM

android - 添加 TextViews 并更新 ViewGroup 以显示 Textviews

Javascript 界面不适用于 android 4.2

android - Jetpack compose 中的 ConstraintLayout 问题

android - GCM (Google Cloud Messaging) 使用什么技术?