简体   繁体   English

CollapsingToolbarLayout 不滚动

[英]CollapsingToolbarLayout not scrolling

I've looked through similar questions on SO and also the docs.我已经查看了关于 SO 和文档的类似问题。 I can't seem to figure out why this isn't working.我似乎无法弄清楚为什么这不起作用。 The CollapsingToolbar doesn't collapse. CollapsingToolbar 不会折叠。 The recyclerview slides underneath it when scrolling it up the screen.向上滚动屏幕时,回收视图会在其下方滑动。 Any suggestions are appreciated.任何建议表示赞赏。

Note: I've tried adding the注意:我试过添加

        app:layout_behavior="@string/appbar_scrolling_view_behavior"

to the recyclerview instead of the SwipeRefreshLayout and also have tried removing the SwipeRefreshLayout altogether.到 recyclerview 而不是 SwipeRefreshLayout 并且还尝试完全删除 SwipeRefreshLayout。

Below is my layout file.下面是我的布局文件。

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/logo"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:paddingBottom="28dp"
            android:paddingLeft="@dimen/list_side_margin"
            android:paddingRight="@dimen/list_side_margin"
            android:scrollbarStyle="outsideOverlay" />
    </android.support.v4.widget.SwipeRefreshLayout>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:src="@drawable/ic_add_white"
        app:layout_anchor="@id/recycler_view"
        app:layout_anchorGravity="bottom|right|end" />

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

不要设置 recycler.isNestedScrollingEnabled = false

The answer is to add答案是添加

app:layout_scrollFlags="scroll|exitUntilCollapsed

to the Toolbar.到工具栏。 Having it in the CollapsingToolbarLayout isn't enough.在 CollapsingToolbarLayout 中拥有它是不够的。

将 android:nestedScrollingEnabled="false" 添加到您的回收站视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM