在我的项目中,我需要为从右到左和从左到右的语言分别创建
layout-ldltr
和layout-ldrtl
布局。当应用程序以从右到左的语言启动时,一切都很好。但是当方向改变时,Android加载layout-ldltr
布局而不是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>
更新
@JohanShogun的评论后,我将android:layoutDirection="rtl"
更改为android:layoutDirection="locale"
,并且大多数项目的问题都得到了解决。
在第一张照片中,所有元素都显示得非常好:
在横屏模式下,在StickyListHeader列表视图中位于屏幕顶部的标题项上,Android使用了ltr布局!: