我在Recyclerview中具有不同的视图持有者,其中之一是多图像视图。多个图像视图不过是Horiontal Scrollview下的线性布局,其中包含动态创建的Image视图。使用滑行加载图像。第一次加载时工作正常。但是,刷新“回收者”视图时,会复制以前帖子中的图像。我也使用了“滑行清除”方法,但是它也不起作用。
这是OnBindViewHolder方法-
{
if (!(viewHolder is AdapterHolders.PostMultiImagesViewHolder holder))
return;
if (item.PostData.PhotoMulti?.Count > 4 || item.PostData.PhotoAlbum?.Count > 4)
{
var imagesList = item.PostData.PhotoMulti ?? item.PostData.PhotoAlbum;
foreach ( var img in imagesList)
{
ImageView imageView = new ImageView(holder.ItemView.Context);
imageView.SetPadding(2, 2, 2, 2);
imageView.SetOnClickListener(holder);
holder.layout.AddView(imageView);
FullGlideRequestBuilder.Load(img.Image).Placeholder(Resource.Drawable.ImagePlacholder).FitCenter().Error(Resource.Drawable.ImagePlacholder).Into(imageView);
ImageViewList.Add(imageView);
}
}
break;
这是OnCreateViewHolder方法
{
itemView = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.Post_Content_MultiImages_Layout, parent, false);
var vh = new AdapterHolders.PostMultiImagesViewHolder(itemView, this, PostClickListener);
Console.WriteLine("WoLog: NativePostAdapter / OnCreateViewHolder >> " + (JavaSystem.CurrentTimeMillis() - startTime) + " PostModelType = MultiImages" + viewType);
return vh;
}
这是OnViewRecycled方法
else if (holder is AdapterHolders.PostMultiImagesViewHolder viewHolder12)
{
foreach (ImageView img in ImageViewList)
{
//viewHolder12.layout.GetChildAt(img.Id);
Glide.With(ActivityContext).Clear(img);
}
}
尝试呼叫ImageViewList.clear();
ImageViewList.Add(imageView);
之前