Ali Sadeghi Ali Sadeghi - 2 months ago 35
Android Question

Right to left navigation drawer menu using android design support library

I'm using the android design support library and i want to know how can i have a right to left navigation drawer,I set the gravity to right but only the navigation drawer itself moved to right, I want to know how can i put the menu items on the right side ?
Navigation View :

<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:foregroundGravity="right"
app:headerLayout="@layout/header"
app:menu="@menu/drawer" />


Drawer layout :

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity"
android:layout_gravity="right">


menu :

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/one"
android:checked="false"
android:icon="@drawable/account"
android:title="First Item"></item>

<item
android:id="@+id/two"
android:checked="false"
android:icon="@drawable/filter"
android:title="Second Item"></item>

<item
android:id="@+id/three"
android:checked="false"
android:icon="@drawable/human"
android:title="Third Item"></item>
</group>



and this is my drawer now :
Drawer

thanks in advance

Answer

set direction for navigation view .

android:layoutDirection="rtl"

 <android.support.design.widget.NavigationView
    android:layoutDirection="rtl"
    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_main"
    app:menu="@menu/activity_main_drawer" />

enter image description here