如何在NavigationView中更改项目的重力

时间:2017-03-16 06:11:35

标签: android navigation-drawer right-to-left navigationview

enter image description here

我需要定位我的navView项目(rtl),我在google和stackoverflow中搜索但我在NavigationView中找不到除此行之外的任何内容:

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

似乎在api 17下面不支持..

    <android.support.design.widget.NavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    android:layoutDirection="rtl"
    android:textDirection="rtl"
    android:id="@+id/navigationView"
    app:itemTextColor="@color/darkerMilk"
    app:menu="@menu/xxx_drawermenu"
    android:layout_marginTop="-1dp"/>

菜单项

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="Inbox"
      android:id="@+id/nav_item_inbox"
      android:icon="@drawable/arrow"/>

<item android:title="Sent"
      android:id="@+id/nav_item_sent"
      android:icon="@drawable/arrow"/>

<item android:title="Drafts"
      android:id="@+id/nav_item_draft"
      android:icon="@drawable/arrow"/>

navigationView类

mNavigationView = (NavigationView) findViewById(R.id.navigationView) ;


 mNavigationView.setNavigationItemSelectedListener(new 
 NavigationView.OnNavigationItemSelectedListener() {
         @Override
         public boolean onNavigationItemSelected(MenuItem menuItem) {
           // mDrawerLayout.closeDrawers();

             if (menuItem.getItemId() == R.id.nav_item_sent) {
             }

            if (menuItem.getItemId() == R.id.nav_item_inbox) {
            }

            if (menuItem.getItemId() == R.id.nav_item_exit) {

            }


             return false;
        }

    });

你知道任何解决方法吗??

1 个答案:

答案 0 :(得分:0)

在NavigationItem标记上只需添加

android:layoutDirection="locale"

像这样

<android.support.design.widget.NavigationView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layoutDirection="rtl"
android:textDirection="rtl"
android:id="@+id/navigationView"
app:itemTextColor="@color/darkerMilk"
app:menu="@menu/xxx_drawermenu"
android:layout_marginTop="-1dp"
android:layoutDirection="locale"/>