相关疑难解决方法(0)

在nestedscrollview中无限滚动的Recyclerview触发onScrolled

我在nestedscrollview中有recyclerview:

   <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>
Run Code Online (Sandbox Code Playgroud)

Recyclerview有OnScrollListener正在处理从这个例子采取无休止的滚动:https://guides.codepath.com/android/Endless-Scrolling-with-AdapterViews-and-RecyclerView.但是看起来nestedscrollview正在触发onScrolled方法,所以整个项目列表都会立即加载.

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

请注意,一切都适用于recyclerview,而不是在nestedscrollview中

android endlessscroll android-recyclerview android-nestedscrollview

11
推荐指数
1
解决办法
2253
查看次数

当setNestedScrollingEnabled为false时,Recyclerview onscrolllistener无法正常工作

我想实现分页recyclerView,为此我添加addOnScrollListenerrecyclerView但是我在RecyclerView.OnScrollListener设置时没有工作的麻烦rvGridExplore.setNestedScrollingEnabled(false);

但当我删除rvGridExplore.setNestedScrollingEnabled(false);它工作正常,我不知道如何处理这个.

这是代码:

rvGridExplore = (RecyclerView) view.findViewById(R.id.rvGridExplore);
        final GridLayoutManager glm = new GridLayoutManager(context,2);
       // rvGridExplore.setNestedScrollingEnabled(false);
        rvGridExplore.setLayoutManager(glm);

       // final int visibleItemCount,totalCount,pastVisibleItems;
        rvGridExplore.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                Log.v("scrollll","state changed");
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy > 0) {
                    int totalCount = glm.getItemCount();
                    int visibleItemCount = glm.getChildCount();
                    int pastVisibleItems = glm.findFirstVisibleItemPosition();
                    if (loading) { …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview

10
推荐指数
3
解决办法
1万
查看次数