Glide, RecyclerView: Glide returns 同一张图片,即使数据输入不同

Glide, RecyclerView: Glide returns the same picture over and over again even with different data inputs

我的房车有问题。 我正在将 mp3 的封面艺术加载到字节数组中,然后使用 glide 将字节数组加载到图像中 (vh.coverArt)。但是,当我使用 glide 而不是仅使用 .SetImageBackground(image) 设置图像时,一遍又一遍地滑动 returns 相同的图片。

我知道我每次调用它时都会给它不同的数据,但是每次只有第一张图片返回到我的图像中。这是我在 RV 中绑定 ViewHolder 的整个函数:

 private async Task SetContentAsync(PhotoViewHolder vh, int position)
        {
            string SongName = "";
            string ArtistName = "";
            Bitmap bitmap = null;
            byte[] data = null;

            try
            {
                reader.SetDataSource(mp3Obj[position].Mp3Uri);
            }
            catch { }


            await Task.Run(() => // cause problems with the reload
            {
                SongName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyTitle);
                ArtistName = reader.ExtractMetadata(MediaMetadataRetriever.MetadataKeyArtist);

                data = reader.GetEmbeddedPicture();

                if (data != null)
                {
                    try
                    {
                        bitmap = BitmapFactory.DecodeByteArray(data, 0, data.Length);
                    }
                    catch { }
                }
            });



            ((Activity)ctx).RunOnUiThread(() =>
            {
                vh.SongName.SetTypeface(tf, TypefaceStyle.Normal);
                vh.AristName.SetTypeface(tf, TypefaceStyle.Normal);
                vh.SongName.Text = SongName;
                vh.AristName.Text = ArtistName;

                try
                {
                    if (bitmap != null && data != null)
                    {


                        Glide
                             .With(ctx)
                             .Load(data)
                             .Apply(RequestOptions.CircleCropTransform()).Into(vh.CoverArt);

                        ConvertBitmapToBackground(bitmap, vh, false); // Set As Backgorund, blurry and black ( just sets the variable)

                    }
                    else // because recycler items inherit their shit and if it is altered it just shows views were there shouldnt be any ... 
                    {
                           vh.CoverArt.SetImageResource(Resource.Drawable.btn_musicalnote);
                           ConvertBitmapToBackground(bitmap, vh, true); // Set As Backgorund, blurry and black ( just sets the variable)             
                    }
                }
                catch { }

            });


        }

我是否错误地使用了 Glide?

您应该将 DiskCacheStrategy 设置为 NONE 并将 skipMemoryCache 设置为 true,如下所示:

Glide.with(DemoActivity.this)
.load(Uri.parse("file://" + imagePath))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(mImage);