RecyclerView and SwipeRefreshLayout

后端 未结 12 1840
再見小時候
再見小時候 2020-12-22 15:46

I\'m using the new RecyclerView-Layout in a SwipeRefreshLayout and experienced a strange behaviour. When scrolling the list back to the top sometim

12条回答
  •  隐瞒了意图╮
    2020-12-22 16:13

    I run into the same problem. My solution is overriding onScrolled method of OnScrollListener.

    Workaround is here:

        recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
    
        }
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            int offset = dy - ydy;//to adjust scrolling sensitivity of calling OnRefreshListener
            ydy = dy;//updated old value
            boolean shouldRefresh = (linearLayoutManager.findFirstCompletelyVisibleItemPosition() == 0)
                        && (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) && offset > 30;
            if (shouldRefresh) {
                swipeRefreshLayout.setRefreshing(true);
            } else {
                swipeRefreshLayout.setRefreshing(false);
            }
        }
    });
    

提交回复
热议问题