RecyclerView 滑动时的优化处理,在滑动时停止加载图片,在滑动停止时开始加载图片,这里用了Glide.pause 和Glide.resume.这里为了避免重复设置增加开销,设置了一个标志变量来做判断。
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_DRAGGING || newState == RecyclerView.SCROLL_STATE_SETTLING) {
sIsScrolling = true;
Glide.with(VipMasterActivity.this).pauseRequests();
} else if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (sIsScrolling == true) {
Glide.with(VipMasterActivity.this).resumeRequests();
}
sIsScrolling = false;
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
您可能感兴趣的文章:RecyclerView+CardView实现横向卡片式滑动效果RecyclerView滑动到指定Position的方法Android中RecyclerView实现横向滑动代码Android中RecyclerView嵌套滑动冲突解决的代码片段android RecyclerView侧滑菜单,滑动删除,长按拖拽,下拉刷新上拉加载Android实现评论栏随Recyclerview滑动左右移动Android 滑动监听RecyclerView线性流+左右划删除+上下移动Android开发中RecyclerView模仿探探左右滑动布局功能Android RecyclerView滑动删除和拖动排序Android嵌套RecyclerView左右滑动替代自定义viewRecyclerView实现探探卡片滑动效果