android - 如何在 CollapsingToolbarLayout 中滚动 Recyclerview

标签 android android-recyclerview android-collapsingtoolbarlayout

我在 CollapsingToolbarLayout 中有 recyclerview,我希望它可以滚动,但事实并非如此。当我滚动时,appbar 正在滚动但不是 recyclerview。我尝试了不同的东西,但它不起作用。这是我的代码:

<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/caves_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:theme="@style/AppTheme.AppBarOverlay"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll"
            android:nestedScrollingEnabled="true"
            app:titleEnabled="false">

            <ImageView
                android:id="@+id/caves_backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:background="@mipmap/mount"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop" />



            <android.support.v7.widget.RecyclerView
                android:id="@+id/recycler"
                android:layout_width="match_parent"
                android:layout_height="200dp"/>

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

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

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

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

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

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

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

最佳答案

我找到了解决方案:

recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
            int action = e.getAction();
            switch (action) {
                case MotionEvent.ACTION_MOVE:
                    rv.getParent().requestDisallowInterceptTouchEvent(true);
                    break;
            }
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView rv, MotionEvent e) {

        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

        }
    });

关于android - 如何在 CollapsingToolbarLayout 中滚动 Recyclerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39330867/

相关文章:

android - 无法解析方法setExpandedTitleGravity(int)

Android九补丁content-border不兑现

java - 将 Emoji 从 EditText 发送到服务器

java - 当列表大到足以滚动时,回收器 View 适配器无法正常工作

java - 如何实现recyclerview的水平自动滚动

android - CollapsingToolbarLayout/工具栏边距错误

java - CollapsingToolbar - 与正确的锚定重叠

java - 接下来在已经运行的Android ViewPager中插入新的Fragment

android - 删除带正文的请求(不使用已弃用的 HttpEntity)

android - 如何在单个 recyclerView 中设置两个不同的适配器?