据个人尝试 以下这种方案能准确监听到是否滚动到底部,可以做上拉加载更多
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);
}
}
});