我想实现一个最初不可见的导航抽屉,但是当您单击右侧并使用拖动时,应该从右侧打开我的导航抽屉。我已经根据视频教程编写了代码。我正在使用android studio 2.2.2。在navigation.xml的预览中,正确显示了三个项目。但是当在activity_main.xml中时,我通过使用commend来包含navigation.xml,这些项目不会显示在activity_main.xml的预览中。此外,在模拟器上运行时,当我单击设备右侧然后使用拖动时,不会显示导航抽屉。为什么?
drawer_menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/mnu_edit"
android:title="Edit user info"
/>
<item android:id="@+id/mnu_setting"
android:title="setting"
/>
<item android:id="@+id/mnu_share"
android:title="share"
/>
</menu>
navigation.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="right"
android:layoutDirection="rtl">
<android.support.design.widget.NavigationView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
android:textDirection="rtl"
android:layout_gravity="right"
app:menu="@menu/drawer_menu"
android:fitsSystemWindows="true"
>
</android.support.design.widget.NavigationView>
</android.support.design.widget.CoordinatorLayout>
activity_base.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.mohsen.appnews.myfont.MyTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="hi"
/>
</android.support.design.widget.CoordinatorLayout>
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.mohsen.appnews.MainActivity">
<android.support.v4.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl"
>
<include layout="@layout/activity_base"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include layout="@layout/navigation"
/>
</android.support.v4.widget.DrawerLayout>
</android.support.design.widget.CoordinatorLayout>