listview中有大量图片时,加载有卡顿现象,对此优化。
recyclerView.addOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
switch (newState) {
case AbsListView.OnScrollListener.SCROLL_STATE_FLING:
// 滚动时停止加载图片
Glide.with(activity).pauseRequests();
break;
case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
// 整个滚动事件结束时重新加载图片
Glide.with(activity).resumeRequests();
break;
default:
break;
}
}
}