【发布时间】:2015-09-30 04:48:09
【问题描述】:
在我的项目中,我必须为 Right-To-Left 和 Left-To-Right 语言创建 layout-ldltr 和 layout-ldrtl 布局。
我启动了从右到左语言的应用程序,一切都很好。
但是当方向改变时,android会根据layout-ldrtl加载layout-ldltr布局,尽管当前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">
在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 list view 中的标题项中粘贴在屏幕顶部,Android 使用 ltr 布局!:
【问题讨论】:
标签: android android-layout android-5.0-lollipop right-to-left left-to-right