Recyclerview中onScrollStateChanged的几种状态

编程入门 行业动态 更新时间:2024-10-17 15:30:51

Recyclerview中onScrollStateChanged的<a href=https://www.elefans.com/category/jswz/34/1769370.html style=几种状态"/>

Recyclerview中onScrollStateChanged的几种状态

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;
            }
        }
详细网址:

更多推荐

Recyclerview中onScrollStateChanged的几种状态

本文发布于:2024-02-06 09:39:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1748304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几种   状态   Recyclerview   onScrollStateChanged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!