Glide暂停加载:
Glide.with(context).pauseRequests();
Glide恢复加载:
Glide.with(context).resumeRequests();
配合RecyclerView使用, 只需监听滑动状态的变化
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
switch (newState){
case SCROLL_STATE_IDLE: // The RecyclerView is not currently scrolling.
//当屏幕停止滚动,加载图片
try {
if(getContext() != ) Glide.with(getContext()).resumeRequests();
}
catch (Exception e) {
e.printStackTrace();
}
break;
case SCROLL_STATE_DRAGGING: // The RecyclerView is currently being dragged by outside input such as user touch input.
//当屏幕滚动且用户使用的触碰或手指还在屏幕上,停止加载图片
try {
if(getContext() != ) Glide.with(getContext()).pauseRequests();
}
catch (Exception e) {
e.printStackTrace();
}
break;
case SCROLL_STATE_SETTLING: // The RecyclerView is currently animating to a final position while not under outside control.
//由于用户的操作,屏幕产生惯性滑动,停止加载图片
try {
if(getContext() != ) Glide.with(getContext()).pauseRequests();
}
catch (Exception e) {
e.printStackTrace();
}
break;
}
}