SCROLL_STATE_IDLE: 屏幕停止滑动
SCROLL_STATE_DRAGGING:屏幕滚动且用户使用的触碰或手指还在屏幕上
SCROLL_STATE_SETTLING:由于用户的操作,屏幕产生惯性滑动
方法
resumeRequests()开始加载图片
pauseRequests()停止加载图片
用法
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() != null) 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() != null) 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() != null) Glide.with(getContext()).pauseRequests();
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
详细网址:
https://www.jianshu.com/p/a8621f917407
Recyclerview中onScrollStateChanged的几种状态
最新推荐文章于 2023-07-16 13:14:13 发布