美文网首页
滑动时图片不加载,滑动停止时图片加载

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

作者: 22a5d2ee8385 | 来源:发表于2018-02-21 09:15 被阅读0次
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;  
            }  
        } 

相关文章

网友评论

      本文标题:滑动时图片不加载,滑动停止时图片加载

      本文链接:https://www.haomeiwen.com/subject/womntftx.html