gpt4 book ai didi

android - Glide ,回收 View : Glide returns the same picture over and over again even with different data inputs

转载 作者:行者123 更新时间:2023-11-29 23:24:32 28 4
gpt4 key购买 nike

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

我知道每次调用时我都会给它不同的数据,但是每次只有第一张图片返回到我的图像中。这是我在 RV 中绑定(bind) 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);

关于android - Glide ,回收 View : Glide returns the same picture over and over again even with different data inputs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53761448/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com