CoordinatorLayout 无法正常工作

CoordinatorLayout doesn't work like I want it to

我的 activity 中有此布局代码。在 ViewPager 中,我有包含 RecyclerView 的片段。当我滚动到列表顶部时,我必须再次滚动它才能展开 CoordinatorLayout。我怎样才能在一个无缝滚动中做到这一点:

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:fitsSystemWindows="true"
    android:background="?colorPrimary">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:expandedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
        app:expandedTitleMarginStart="20dp"
        app:expandedTitleMarginBottom="10dp"
        app:contentScrim="?attr/colorPrimary"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_collapseMode="parallax"
            android:scaleType="centerCrop"
            android:transitionName="obrazek"
            android:src="@drawable/placer" />

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/gradient" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:contentInsetStart="40dp"
            app:layout_scrollFlags="scroll|enterAlways"
            app:layout_collapseMode="pin"
             />

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

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

<LinearLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal"
        android:background="?attr/colorPrimary"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <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"/>

</LinearLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    app:fabSize="normal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    app:elevation="6dp"
    app:layout_anchor="@id/main_content"
    app:layout_anchorGravity ="bottom|right|end"
    android:src="@drawable/ic_directions_run_white_48dp" />

您不需要为 TabLayoutViewPager 设置 app:layout_behavior。将 app:layout_behavior 设置为仅 LinearLayout 就足够了。