在方向改变后加载"layout-ldltr"布局的android bug是否对"layout-ldrtl"?

Say*_*emi 8 android android-layout right-to-left left-to-right android-5.0-lollipop

萨拉姆.

在我的项目中,我必须为语言和语言创建两者layout-ldltrlayout-ldrtl布局.Right-To-LeftLeft-To-Right

我启动了从右到左语言的应用程序,每件事都很好.但是当方向改变时,android加载layout-ldltr布局反对layout-ldrtl,虽然当前Locale设置为RTL语言!

怎么解决这个问题?!

AndroidManifest.xml

<application
    android:name=".QuranApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
Run Code Online (Sandbox Code Playgroud)

layout-ldrtl\activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layoutDirection="rtl">

<include layout="@layout/toolbar" />

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:layoutDirection="rtl">

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutDirection="rtl"/>

    <include
        layout="@layout/list_view"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

UPDATE

在@JohanShogun评论之后,我改变android:layoutDirection="rtl"android:layoutDirection="locale"并解决了大多数项目的问题.

在第一张照片中,所有元素都显示非常好:

纵向

在横向模式下,在粘贴在屏幕顶部的标题项中的StickyListHeader列表视图中,从ltr布局使用android !:

景观方向

Joh*_*gun 6

如果你有一个带有layout-land的文件夹,它将占用总统而不是layout-ldrtl等你可能需要为layout-land-ldrtl等创建文件夹.

另一种可以处理从右到左和从左到右布局的方法是保留一个写入的布局文件以使用这两个版本.

在LinearLayout等上有一个属性:

android:layoutDirection
Run Code Online (Sandbox Code Playgroud)

您可以将其设置为"Locale"的值,您的水平布局将按顺序翻转.

而不是使用align_left/align_rightgravity_left/gravity_right使用,而不是align_start/align_endgravity_start/gravity_end(这适用于所有left/right属性).开始和结束标记取决于布局方向.如果用户拥有了一个语言环境ltr 开始是左结束是正确的,如果用户有一个区域与rtl 开始是正确的,并最终被留下.

我个人更喜欢使用编写的布局文件来处理两者rtl并且ltr使用单独的布局文件,如果保留不同的文件,很容易错过一个版本的更新,从而导致糟糕的用户体验.

同时将布局移动到布局文件夹(删除"-ldrtl"),然后将全部更改android:layoutDirection="rtl"android:layoutDirection="locale".