优化在了哪里?
只有在Reyclerview停止滑动的时候 再加载图片以此来减少内存和网络的开销
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@androidx.annotation.NonNull RecyclerView recyclerView, int newState) {
switch (newState){
case RecyclerView.SCROLL_STATE_IDLE:
//滑动停止时
try {
if(getContext()!=null){
Glide.with(getContext()).resumeRequests();
}
}catch (Exception e){
}
break;
case RecyclerView.SCROLL_STATE_DRAGGING:
case RecyclerView.SCROLL_STATE_SETTLING:
//滑动时
try {
if(getContext()!=null){
Glide.with(getContext()).pauseRequests();
}
}catch (Exception e){
}
break;
}
}
@Override
public void onScrolled(@androidx.annotation.NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});