方向更改后,加载“ layout-ldltr”布局中的android bug是否针对“ layout-ldrtl”?

问题描述 投票:8回答:1

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

我启动了从右到左语言的应用程序,一切都很好。但是,当方向更改时,尽管当前layout-ldltr设置为RTL语言,但android相对layout-ldrtl加载了Locale布局!!

如何解决此问题?

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">

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>

UPDATE

在@JohanShogun发表评论后,我将android:layoutDirection="rtl"更改为android:layoutDirection="locale",并且大多数项目已解决问题。

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

Portrait orientation

在横向模式下,位于屏幕顶部的标题项中的StickyListHeader list view中,Android从ltr​​布局使用!:

Lanscape orientation

android android-layout android-5.0-lollipop right-to-left left-to-right
1个回答
6
投票

如果您的文件夹中有layout-land-ldrtl等,您可能会接任主席。您可能需要为layout-land-ldrtl等创建文件夹。

您可以处理从右到左和从左到右的布局的另一种方法是保留一个布局文件,该文件被编写为可用于两个版本。

在LinearLayout等上有一个属性:

android:layoutDirection

您可以将其设置为“ Locale”的值,并且水平布局将翻转顺序。

而不是使用align_left/align_rightgravity_left/gravity_right来代替使用align_start/align_endgravity_start/gravity_end(适用于所有left/right属性)。开始和结束标签取决于布局方向。如果用户的语言环境为ltr 开始左端end右]],如果用户的语言环境为rtl start右端end左] >。

[我个人更喜欢使用为rtlltr编写的布局文件,而不是使用单独的布局文件,如果保留不同的文件,很容易错过一个版本的更新,从而导致糟糕的用户体验。] >

也将布局移动到布局文件夹(删除"-ldrtl",然后将所有android:layoutDirection="rtl"更改为android:layoutDirection="locale"

© www.soinside.com 2019 - 2024. All rights reserved.