Glide: Image was hidden when RecyclerView scrolled

Created on 28 Feb 2018  路  8Comments  路  Source: bumptech/glide

I have problem when using with RecyclerView.
If item row was display, It would worked fine. But when I scrolled up and down (this item was hided and showed again) the image in this item didn't show.
Here is my code, I called in onBindViewHolder:

    public void loadChatPhoto(final Context context, String url, final ImageView ivImage) {
        GlideApp.with(context)
                .load(url)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.color.divider)
                .error(R.mipmap.default_photo)
                .into(ivImage);
    }
question stale

All 8 comments

Does using waitForLayout resolve the issue?

Glide.with(context)
  .load(url)
  .into(imageView)
  .waitForLayout();

Thanks, I worked !
And could you please help me resolve the next issue ?
I used Glide to setImage to Image that was added this :

android:maxHeight="@dimen/size_230dp"
android:maxWidth="@dimen/size_250dp"

But ImageView didn't resize after the picture loaded completely

Did I forget something ?

maxWidth/maxHeight will not resize anything, they just prevent your view from being laid out at a larger size.

So, what can I do to fix it ?
Because I don't want my picture display very large, so i need to setMax size for it

I'm not actually sure what you're trying to do? What are you expecting to happen? How does it compare to what is actually happening?

I fixed it.
And it's my solution:
````java
GlideApp.with(context)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.lazy_icon)
.error(R.mipmap.default_photo)
.into(new SimpleTarget() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition transition) {
try {
Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
int btmWidth = bitmap.getWidth();
int btnHeight = bitmap.getHeight();
float rate = btmWidth * 1.0f / btnHeight;

// changed you maxWidth = R.dimen.size_230dp;
// And maxHeight too, anythings you want
float ivWidth = context.getResources().getDimensionPixelSize(R.dimen.size_230dp);
float ivHeight = context.getResources().getDimensionPixelSize(R.dimen.size_250dp);
if(rate > 1) {
ivHeight = ivWidth / rate;
} else {
ivWidth = ivHeight * rate;
}

                        ViewGroup.LayoutParams param = ivImage.getLayoutParams();
                        param.width = (int)ivWidth;
                        param.height = (int)ivHeight;
                        ivImage.setLayoutParams(param);
                        ivImage.setImageBitmap(bitmap);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

````

This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MrFuFuFu picture MrFuFuFu  路  3Comments

technoir42 picture technoir42  路  3Comments

Tryking picture Tryking  路  3Comments

Ncit picture Ncit  路  3Comments

mttmllns picture mttmllns  路  3Comments