Recyclerview在nestedscrollview中无限滚动,触发onScrolled [英] Recyclerview with endless scrolling in nestedscrollview, triggers onScrolled

查看:116
本文介绍了Recyclerview在nestedscrollview中无限滚动,触发onScrolled的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在nestedscrollview中有recyclerview:

I have recyclerview in the nestedscrollview:

   <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <org.apmem.tools.layouts.FlowLayout
                android:id="@+id/filter_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/green_main"
                android:paddingLeft="@dimen/small_horizontal_margin"
                android:paddingRight="@dimen/small_horizontal_margin"
                />

            <android.support.v7.widget.RecyclerView
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clipToPadding="false"
                android:scrollbars="vertical"
                android:paddingTop="@dimen/vertical_margin"/>

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

Recyclerview具有OnScrollListener,它正在处理从此示例中获取的无限滚动: https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView .但是,似乎nestedscrollview会触发onScrolled方法,因此整个项目列表会立即加载.

Recyclerview have OnScrollListener which is handling endless scrolling taken from this example: https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView. However it seems like nestedscrollview is triggering onScrolled method, so whole list of items is loaded straight away.

问题: 我如何防止这种行为?

Question: How I can prevent this beheviour?

请注意,一切都可以与nestedscrollview中没有的recyclerview完美配合

Note, everything works perfect with recyclerview which isn't in nestedscrollview

推荐答案

尝试在RecyclerView上禁用嵌套滚动:

Try disabling nested scrolling on the RecyclerView:

recyclerView.setNestedScrollingEnabled(false);

解决了我错误的嵌套滚动问题.让我知道是否有帮助.

Solved my issue with errant nested scrolling. Let me know if that helps.

这篇关于Recyclerview在nestedscrollview中无限滚动,触发onScrolled的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆