我正在使用 android 设计支持库,我想知道如何拥有从右到左的导航抽屉,我将重力设置为右侧,但只有导航抽屉本身移动到右侧,我想知道如何将右侧的菜单项?
导航视图:
<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" />
抽屉布局:
<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 :
提前致谢
我可以通过添加 DrawerLayout 来使其工作,如下所示:
<?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:gravity="right"
android:fitsSystemWindows="true"
tools:openDrawer="right">
<include
layout="@layout/app_bar_main"
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_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
然后添加到您的活动中before setContentView(R.layout.main_activity);
:
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
这仅适用于 API 17+
Result:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)