我们如何在nesetedscroll视图内的recyclerView中进行分页?

问题描述 投票:0回答:1

这里是我在滚动(嵌套滚动视图)上点击“加载更多”时发生的错误。该功能正常工作。似乎数据绑定中存在问题。

android android-recyclerview pagination android-nestedscrollview
1个回答
0
投票

在xml中将recyclerview的嵌套滚动设置为false

android:nestedScrollingEnabled="false"

在嵌套滚动视图上应用分页

mNestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
        if(v.getChildAt(v.getChildCount() - 1) != null) {
            if ((scrollY >= (v.getChildAt(v.getChildCount() - 1).getMeasuredHeight() - v.getMeasuredHeight())) &&
                    scrollY > oldScrollY) {

                visibleItemCount = mLayoutManager.getChildCount();
                totalItemCount = mLayoutManager.getItemCount();
                pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition();

                if (isLoadData()) {
                    if ((visibleItemCount + pastVisiblesItems) >= totalItemCount) {
                        //Load your data here
                    }
                }
            }
        }
    }
});
public boolean isLoadData(){
    return itemsReturnedPerPageCount > 0;
}
© www.soinside.com 2019 - 2024. All rights reserved.