glide4.8 加载长图模糊

542 阅读1分钟
private void loadImage(String reportDetailUrl) {
        Glide.with(this)
                .applyDefaultRequestOptions(new RequestOptions()
                        .format(DecodeFormat.PREFER_ARGB_8888)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                )
                .load(reportDetailUrl)
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        vPlaceholder.setVisibility(View.GONE);
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        vPlaceholder.setVisibility(View.GONE);
                        return false;
                    }
                })
                .into(new CustomViewTarget(ivReportDetailImg) {

                    @Override
                    public void onLoadFailed(@Nullable Drawable errorDrawable) {

                    }

                    @Override
                    public void onResourceReady(@NonNull Object resource, @Nullable Transition transition) {
                        if(resource instanceof BitmapDrawable){
                            ivReportDetailImg.setImageBitmap(((BitmapDrawable) resource).getBitmap());
                        }
                    }

                    @Override
                    protected void onResourceCleared(@Nullable Drawable placeholder) {

                    }
                });
    }