【发布时间】:2016-08-09 10:55:40
【问题描述】:
我需要将导航菜单项向右对齐。 我阅读了许多文章和问题和答案,但我找不到我的项目有什么问题。 这是我的 xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="right">
<include
layout="@layout/content_activity_home"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_activity_home"
app:menu="@menu/activity_home_drawer" />
这是activity_home_drawer.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/menu_account"
android:icon="@drawable/ic_profile"
android:title="حساب کاربری" />
<item
android:id="@+id/menu_logout"
android:icon="@drawable/ic_sign_out"
android:title="خروج از حساب" />
</group>
我可以让抽屉本身从右侧打开,但 NavigationView 的元素仍保持从左到右。你可以在这里看到结果:
如您所见,菜单项不是从右到左的。如何使它们成为 rtl?
【问题讨论】:
-
我将此代码添加到我的应用程序中,但我收到此错误:“没有找到重力左侧的抽屉视图”
-
@Navid_pdp11 将您的代码发送给我以修复它
-
我将 Direction RTL 添加到我的抽屉,它从现在开始打开 :)
标签: android xml user-interface right-to-left navigation-drawer