快捷搜索:

这里用了Glide.pause

RecyclerView 滑动时的优化处理

在滑动时停止加载图片,在滑动停止时开始加载图片,这里用了Glide.pause 和Glide.resume.这里为了避免重复设置增加开销,设置了一个标志变量来做判断。

mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {@Overridepublic 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; }}@Overridepublic void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy);}});

本文由澳门新葡萄京8455官网发布于澳门新葡萄京8455官网,转载请注明出处:这里用了Glide.pause

您可能还会对下面的文章感兴趣: