android - 如何在项目出现之前在 android 中为项目加载带有毕加索的图像?
问题描述
我有一个回收站视图,它的每个项目都有一个毕加索加载该图像的图像。
当我在毕加索加载图像之前滚动回收器视图时,我会显示一个占位符,但在大多数情况下,毕加索很慢并且会出现占位符。
请注意,我在 onBindViewHolder 中加载图像,并且我想以在大多数情况下不会出现占位符的方式加载图像。
public void onBindViewHolder(...){
Picasso.with(context)
.load(url)
...
}
解决方案
不会为您的所有项目调用 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 时,它将从缓存中加载图像。
推荐阅读
- php - 使用 PHP 将 txt 数据文件转换为结构化 JSON
- php - 如何在 PHP 中从 Dropbox 中列出文件名
- telegram - 有没有一种方法可以在不登录 Telegram 的情况下修改 api id 和/或 api 哈希?
- python - 如何使用 Pandas 将逗号分隔的字符串列转换为单个因素?
- javascript - Html未显示Angular中组件的列表
- r - 使用 R 生成所有可能的 DAG
- javascript - 即使 response.ok 为假,Fetch Api .then 函数也会运行
- django - Eurodns + Django + 动态 IP
- c - c中的堆内存
- qt - 编译 Qt 6.2.1:“qplatformdefs.h”:没有这样的文件或目录