Android 将所有视图转移到另一侧

Android shifts all views to the other side

我有一个带有登录页面的应用程序。

如您所见,textViews 和 editTexts 向左移动,但是当我 运行 在以希伯来语作为其语言的设备中时,所有这些视图都向右移动。这可能是因为希伯来语是从右向左书写的。我的问题是如何阻止这种情况发生?

将以下行添加到布局的根视图中:

    android:layoutDirection="ltr"

这会强制布局方向为从左到右,而不是基于语言环境。

您可以将 android:layoutDirection="ltr" 添加到布局中。

如果没有您的代码很难判断,但我认为您需要做的就是将 android:layoutDirection="ltr" 添加到您的布局中。

这将告诉您的布局是 ltr,而不是根据设备语言更改

这与 RTL(从右到左)本机支持有关。

在您的 Manifest 中,您可以为您的应用进行全局配置:

android:supportsRtl="false"

official doc中:

Declares whether your application is willing to support right-to-left (RTL) layouts. If set to true and targetSdkVersion is set to 17 or higher, various RTL APIs will be activated and used by the system so your app can display RTL layouts. If set to false or if targetSdkVersion is set to 16 or lower, the RTL APIs will be ignored or will have no effect and your app will behave the same regardless of the layout direction associated to the user's Locale choice (your layouts will always be left-to-right).

The default value of this attribute is false.

您还可以为每个视图(以及布局)配置 android:layoutDirection 属性,

来自 doc:

Defines the direction of layout drawing. This typically is associated with writing direction of the language script used. The possible values are ltr for Left-to-Right, rtl for Right-to-Left, locale, and inherit from parent view. If there is nothing to inherit, "locale" is used. "locale" falls back to "en-US". ltr is the direction used in "en-US". The default for this attribute is inherit.

和定义文本方向的 android:textDirection 属性。

您必须将 android:supportsRtl="false" 设置为应用程序清单文件中的元素。

you can see more details of RTL tag