android - 具有重复图像的 RecyclerView 项目
问题描述
我使用 RecyclerView v28.0.0 和 Glide Image Library v4.9.0 创建了一个交错列表。
请不要将此问题标记为重复,因为我在发布此问题之前参考了以下项目:
- Glide recyclerview 加载重复图像 RecyclerView 有时会重复项目 http://bumptech.github.io/glide/doc/getting-started.html#listview-and-recyclerview
我使用包含差异回调的 DataBoundListAdapter 创建了一个适配器。
为了确保每个回收者视图项目都获取一个唯一的 ID,我将使用 hashmap 作为:
override fun bind(binding: ItemStockBinding, item: InventoryProductWithSKU, position: Int) {
mContext?.let {
Glide.with(it)
.load(mIdImageMap[item.inventoryProductEntity.id])
.apply(RequestOptions().placeholder(R.drawable.place_holder)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.error(R.drawable.place_holder))
.placeholder(R.drawable.place_holder)
.into(binding.layoutProductImage)
} }
而且,如果 Image 不存在,为了处理这种情况,我会:
Glide.with(mContext!!).clear(binding.layoutProductImage)
binding.layoutProductImage.setImageDrawable(null)
这个问题在我们应用程序的大部分地方都反复出现。请提出任何解决方法。
谢谢。
解决方案
推荐阅读
- node.js - 无法解决“节俭”
- javascript - 打开另一个下拉菜单时关闭下拉菜单
- python - 如何使用 Selenium 从 Python 中的 html 标题中获取文本?
- python - 熊猫每月偏移重复索引
- javascript - 州因国家而异,但城市未因州而异
- cmake - 何时使用 CMAKE_CURRENT_LIST_DIR?
- linq - 使用 ExpandoObject 时表达式树无法正确评估
- git - 让 git 从命令行请求凭据
- amazon-redshift - 在 REDSHIFT 中自动拒绝 Redshift 访问
- linux - msmtp 无法通过 OVH SMTP 将邮件发送到根地址