SwipeRefreshLayout+Recyclerview 预加载

baseRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
    private int minLeftItemCount = 5;
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            int itemCount = layoutManager.getItemCount();
            int lastPosition = layoutManager.findLastCompletelyVisibleItemPosition();
            Log.i("minLeftItemCount", "【总数】" + itemCount + "【位置】" + lastPosition);
            if (lastPosition == layoutManager.getItemCount() - 5) {
                loadMore();//加载更多
            } else {
                if (itemCount > minLeftItemCount) {
                    if (lastPosition == itemCount - minLeftItemCount) {
                        loadMore();//加载更多
                    }
                } else {
                    loadMore();//加载更多
                }
            }
        }
    }


});

你可能感兴趣的:(SwipeRefreshLayout+Recyclerview 预加载)