滑动时图片不加载,滑动停止时图片加载

Glide暂停加载:
Glide.with(context).pauseRequests();

Glide恢复加载:
Glide.with(context).resumeRequests();
配合RecyclerView使用, 只需监听滑动状态的变化

        @Override  
        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() != ) 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() != ) 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() != ) Glide.with(getContext()).pauseRequests();  
                    }  
                    catch (Exception e) {  
                        e.printStackTrace();  
                    }  
                    break;  
            }  
        } 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容