Set visibility of progress bar gone on completion of image loading using Glide library

前端 未结 12 2016
栀梦
栀梦 2020-12-04 11:04

Hi I want to have a progress bar for image which will shown while image loading but when image loading will be completed I want to set it to gone. Earlier I was using Picass

12条回答
  •  执笔经年
    2020-12-04 11:27

    In exception put a condition for show again the ProgressBar

     Glide.with(context)
        .load(image_url)
        .listener(new RequestListener() {
            @Override
            public boolean onException(Exception e, String model, Target target, boolean isFirstResource) {
                if(e instanceof UnknownHostException)
                    progressBar.setVisibility(View.VISIBLE);
                return false;
            }
    
            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target target, boolean isFromMemoryCache, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        })
        .into(imageView);
    

提交回复
热议问题