Android-协调器布局、抽屉布局和片段

Android-协调器布局、抽屉布局和片段,android,android-toolbar,android-design-library,android-coordinatorlayout,Android,Android Toolbar,Android Design Library,Android Coordinatorlayout,我花了一些时间试图实现这一点,并做了一些研究,但无法使其工作。 在Chris Banes的示例中,他在滚动ViewPager时使工具栏滚动。ViewPager直接包含在他的抽屉布局中,就在NaviagtionView之前 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android

我花了一些时间试图实现这一点,并做了一些研究,但无法使其工作。 在Chris Banes的示例中,他在滚动ViewPager时使工具栏滚动。ViewPager直接包含在他的抽屉布局中,就在NaviagtionView之前

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <!-- THIS CONTAINS COORDINATOR LAYOUT with APPBAR LAYOUT + VIEWPAGER -->
    <include layout="@layout/include_list_viewpager"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_view"/>

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

include_list_viewpager文件如下所示:

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_done"/>

</android.support.design.widget.CoordinatorLayout>

我想要一个FrameLayout(或NestedScrollView)而不是ViewPager。然后,当用户单击抽屉布局项时,我可以在其中动态加载片段,所有这些项都会有一个漂亮的动画工具栏。到目前为止,在调用的片段中操作时,我无法使工具栏滚动。我不知道这是否有可能

有人做到了吗?非常感谢任何指针。


<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/mToolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
        android:id="@+id/tab_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

        <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>
    </android.support.v4.widget.DrawerLayout>

</android.support.design.widget.CoordinatorLayout>

CoordinatorLayout必须是所有视图的父视图。DroperLayout获取布局行为。由于您希望与viewpager的元素交互,因此它需要位于抽屉布局的顶视图中。

显示您的布局包含列表viewpager使用cheesesquare应用程序中包含列表viewpager的内容重新编辑此代码不起作用,我已添加了缺少的CoordinatorLayout标记,但我在AppBarLayout中的观点仍然是无所作为,站在那里非常稳定。有什么想法吗?