/** * 设置RecyclerView滚动监听 */ private void setRecyclerViewScrollListener(RecyclerView recyclerView){ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { /** * 滚动监听 * @param recyclerView 获取里面布局管理器 * @param newState 滑动的状态 */ @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager(); if (layoutManager instanceof StaggeredGridLayoutManager) { StaggeredGridLayoutManager lm = (StaggeredGridLayoutManager) layoutManager; int columnCount = lm.getSpanCount(); int positions[] = new int[columnCount]; lm.findLastVisibleItemPositions(positions);//添加可见的最后一行的position数据到数组positions for (int i = 0; i < positions.length; i++) { /** * 判断lastItem的底边到recyclerView顶部的距离 * 是否小于recyclerView的高度 * 如果小于或等于说明滚动到了底部 */ if (positions[i] >= lm.getItemCount() - columnCount) { //这里写要调用的东西 } } } } } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { } }); }
Android RecyclerView监听瀑布流是否滑动到最后一个
最新推荐文章于 2024-09-07 14:18:28 发布