recycleview的加载
有谁知道比较好的第三方开源框架完美支持recycleview的上拉加载?
有谁知道比较好的第三方开源框架完美支持recycleview的上拉加载?
2016-06-07
public class MyLoadMoreScrollListener extends RecyclerView.OnScrollListener { OnLoadMoreListener mOnLoadMoreListener; boolean isSlidingToLast = false; public MyLoadMoreScrollListener(OnLoadMoreListener mOnLoadMoreListener){ this.mOnLoadMoreListener = mOnLoadMoreListener; } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); //dx用来判断横向滑动方向,dy用来判断纵向滑动方向 if (dy > 0) { //大于0表示,正在向右滚动 isSlidingToLast = true; } else { //小于等于0 表示停止或向左滚动 isSlidingToLast = false; } } @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager(); // 当不滚动时 if (newState == RecyclerView.SCROLL_STATE_IDLE) { //获取最后一个完全显示的ItemPosition int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition(); int totalItemCount = manager.getItemCount(); // 判断是否滚动到底部,并且是向右滚动 if (lastVisibleItem == (totalItemCount - 1) && isSlidingToLast) { //加载更多功能的代码 mOnLoadMoreListener.loadMore(); } } } public interface OnLoadMoreListener{ void loadMore(); } }
举报