首页 > 解决方案 > 如何在项目出现之前在 android 中为项目加载带有毕加索的图像?

问题描述

我有一个回收站视图,它的每个项目都有一个毕加索加载该图像的图像。

当我在毕加索加载图像之前滚动回收器视图时,我会显示一个占位符,但在大多数情况下,毕加索很慢并且会出现占位符。

请注意,我在 onBindViewHolder 中加载图像,并且我想以在大多数情况下不会出现占位符的方式加载图像。

public void onBindViewHolder(...){
    Picasso.with(context)
    .load(url)
    ...
}

标签: androidandroid-recyclerviewpicasso

解决方案


不会为您的所有项目调用 BindViewHolder,在您的活动中循环遍历所有列表项,然后调用上述代码。

for (int i=0;i<list.size();i++) { // here I assumed that list is an ArrayList having all URLs.
 Picasso.with(context).load(list.get(i).url).into(imageView); // here imageview is an empty Imageview with zero width and height.
}

上面的代码将加载所有图像并将其保存到缓存中,当您调用适配器 onBindView 时,它将从缓存中加载图像。


推荐阅读