scwang90 / SmartRefreshLayout

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
https://segmentfault.com/a/1190000010066071
Apache License 2.0
24.96k stars 4.96k forks source link

请问有预加载功能吗? #1144

Open YangGui101 opened 4 years ago

YangGui101 commented 4 years ago

自动加载好像是到最底才触发的,请问有自己设置的预加载吗? 例如10条数据,我看到了视图第5条数据就触发加载更多。

Archer-cat commented 4 years ago

同问

jiangzehui commented 4 years ago

同问

000zss commented 2 years ago

同问

guominfang commented 2 years ago
private void initRefreshLayout() {
    binding.refreshLayout.setOnRefreshListener(refreshLayout -> {
        loadData(0);
    });
    binding.refreshLayout.setOnLoadMoreListener(refreshLayout -> {
        loadData(adapter.getCurrentPage() + 1);
    });
    binding.recycleView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            GridLayoutManager lm = (GridLayoutManager) recyclerView.getLayoutManager();
            if (lastVisibleItemPosition != lm.findLastVisibleItemPosition()) {
                lastVisibleItemPosition = lm.findLastVisibleItemPosition();
                Log.d(TAG, "onScrolled: lastVisibleItemPosition=" + lastVisibleItemPosition);
                if (adapter.getItemCount() - lastVisibleItemPosition < 10) {
                    // 提前预加载
                    loadData(adapter.getCurrentPage() + 1);
                }
            }
        }
    });

}

private int oldLoadPage = 0;

private void loadData(int page) {
    // 防止重复加载同一页数据
    if (page != 0 && page == oldLoadPage) return;
    oldLoadPage = page;
   // 访问网络拉取数据

}