ZhangXu
ZhangXu

Reputation: 141

Glide 4.3.1: placeholder() method is not working

I'm using Glide 4.3.1 for loading Image. There are two conditions:

  1. I use into(ImageView) , placeholder() works well
  2. I use into(new SimpleTarget() {...}), placeholder() is not working

This is my code of target:

RequestBuilder drawableTypeRequest = Glide.with(MainActivity.this).asBitmap().load(uri);

drawableTypeRequest.apply(new RequestOptions().override(100, 100).placeholder(R.drawable.add_driver_photo)).into(new SimpleTarget<Bitmap>() {
                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) {

                    imageView.setImageBitmap(resource);
                }
            });

This is my working code

 RequestBuilder drawableTypeRequest = Glide.with(MainActivity.this).asBitmap().load(uri);

 drawableTypeRequest.apply(new RequestOptions().override(100, 100).placeholder(R.drawable.add_driver_photo)).into(imageView);

And I find somebody ask similar question in stackoverflow: glide:4.3.1 override and placeholder features not work, But it not my disk.

Can anybody solve my doubt? Thank you!

Upvotes: 0

Views: 836

Answers (1)

Realank
Realank

Reputation: 28

As a ten years android developer, I should tell you , if you use the first codes, Glide don't know which target the placeholder should place, you don't assign a imageView to the placeholder, as we talked face to face, you should use ImageViewTarget instead of SimpleTarget, the constructor of ImageViewTarget has a param view, you can pass your imageView into there

Upvotes: 1

Related Questions