RecyclerView 監聽滾動到底部
阿新 • • 發佈:2019-02-08
據個人嘗試 以下這種方案能準確監聽到是否滾動到底部,可以做上拉載入更多
protected boolean isSlideToBottom(RecyclerView recyclerView) { if (recyclerView == null) return false; if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange()) return true; return false; }
recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); LogUtils.d("------->isSlideToBottom:" + isSlideToBottom(recyclerView)); if (isSlideToBottom(recyclerView)) { srlLayout.setEnabled(true); } } });