Android 在向上滚动工具栏上具有折叠工具栏的回收器视图不会折叠

Android 在向上滚动工具栏上具有折叠工具栏的回收器视图不会折叠,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我有一个带有FrameLayout的活动,我在其中添加或替换了几个片段。该活动使用折叠工具栏布局 在第一个场景中,我添加了一个带有NestedScrollView、LinearLayout、CardView和TextView的片段。一切正常,滚动和折叠/展开工具栏 在第二个场景中,我使用SwipeRefreshLayout和RecyclerView向FrameLayout添加了一个片段,但问题是当我向上滚动工具栏时,工具栏没有折叠 在本视频中,您可以看到问题: 活动布局: <android

我有一个带有FrameLayout的活动,我在其中添加或替换了几个片段。该活动使用折叠工具栏布局

在第一个场景中,我添加了一个带有NestedScrollView、LinearLayout、CardView和TextView的片段。一切正常,滚动和折叠/展开工具栏

在第二个场景中,我使用SwipeRefreshLayout和RecyclerView向FrameLayout添加了一个片段,但问题是当我向上滚动工具栏时,工具栏没有折叠

在本视频中,您可以看到问题:

活动布局:

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

    <android.support.design.widget.CollapsingToolbarLayout

     ................

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

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

    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </FrameLayout>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/printerModels"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end"
    style="@style/FabStyle"/>
<android:android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:paddingTop="24dp"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="5dip"
        android:layout_margin="15dp"
        android:layout_marginBottom="50dp"
        app:cardCornerRadius="3dp"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_margin="@dimen/model_detail_card_view_margin">

            ..........
            ..........
            //Several textviews here
        </LinearLayout>

    </android.support.v7.widget.CardView>
</LinearLayout>

</android:android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/contentView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_users"
        android:scrollbars="vertical"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

    <include
        layout="@layout/view_progress"
        />

    <include
        layout="@layout/view_retry"
        />

    <!--</LinearLayout>-->

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


您的坐标布局:

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

            <android.support.design.widget.CollapsingToolbarLayout

             ................

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

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

 //This  <include layout="@layout/content_main" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/printerModels"
            app:layout_anchor="@id/appbar"
            app:layout_anchorGravity="bottom|right|end"
            style="@style/FabStyle"/>


禁用xml中RecyclerView的嵌套滚动

android:nestedScrollingEnabled="false"

将其设置为tecyclerView.setNestedScrollingEnabled(true)后,没有任何更改;将框架布局放在嵌套的滚动视图中,并在其中替换片段,并为第一个场景创建不同的片段布局,其中线性布局为父级如果我放置嵌套的滚动视图,则永远不会调用onBindViewHolder,并且回收器视图没有填充数据onBindViewHolder和nestedScollview…回收视图将位于fragmnet中,该fragmnet将连接到nestedView中的framelayout,nestedView包含在折叠布局中
android:nestedScrollingEnabled="false"