如何以编程方式在 DrawerLayout 中包含布局并平滑拖动导航​​视图?

How to include layouts in DrawerLayout programatically and smooth dragging of navigation view?

<?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:fitsSystemWindows="true"
    tools:openDrawer="start">

    <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="start"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <include layout="@layout/nav_header_main" />
        </LinearLayout>

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>


DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        View child = getLayoutInflater().inflate(R.layout.app_bar_main, null);
        drawer.addView(child);

我使用此代码以编程方式将不同的 Childs 添加到抽屉布局。当我以编程方式添加子项时意味着导航抽屉无法正常工作我的意思是它可以被拖出但不能拖动 in.When 我触及侧面意味着它 closing.Can 任何人都知道如何解决这个问题。提前致谢。

不要包含在抽屉布局中,而是尝试包含在协调器布局中。