Right to left menu items Android in NavigationView

后端 未结 2 728
失恋的感觉
失恋的感觉 2020-12-19 14:38

im beginer of android. i design a navigation drawer like this:

as you see all items in menu are on the right Except \"SubHeader\".

how can i move \"SubHeade

相关标签:
2条回答
  • 2020-12-19 15:23

    Try adding these attributes to NavigationView in your layout file.

    android:layoutDirection="rtl"
    android:textDirection="rtl"
    

    If no other way. You should use custom layout

    example:

    <android.support.design.widget.NavigationView
      android:layoutDirection="rtl"
      android:id="@+id/navigation_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>
     <LinearLayout>
     // code xml here
     </LinearLayout>
     <android.support.design.widget.NavigationView/>
    
    0 讨论(0)
  • 2020-12-19 15:24

    try this make your menu gravity="right" of your menu item

    <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:gravity="end"
     android:layoutDirection="rtl"
     android:layout_gravity="end">
    
     <group android:checkableBehavior="single"
        android:layout_gravity="end"
        android:gravity="end">
    
        <item
            android:id="@+id/nav_1"
            android:icon="@drawable/abc"
            android:gravity="end"
            android:layout_gravity="end"
            android:title="menu title"/>
         </group>
    </menu>
    

    and make your navigation view like this

    <android.support.design.widget.NavigationView
          android:layoutDirection="rtl"
          android:id="@+id/navigation_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" />
    
    0 讨论(0)
提交回复
热议问题