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); } });
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。