好记性不如烂笔记
滑动冲突
rvHotProduct.setNestedScrollingEnabled(false); // 解决滑动不顺畅
rvHotProduct.setHasFixedSize(false); // 解决滑动不顺畅
rvHotProduct.setFocusable(false); // 防止RecyclerView加载数据的时候抢占焦点,把顶部view遮挡了
自动加载更多
// 加载更多
rvHotProduct.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
// 滚到底部
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
int lastVisibleItemPosition = manager.findLastCompletelyVisibleItemPosition();
int totalItemCount = manager.getItemCount();
if ((lastVisibleItemPosition + 1) == totalItemCount) {
// 加载更多
if (!isLastPage) {
requestHotProduct(++pageNo);
}
}
}
}
});
网友评论