android - Glide clear() 方法无法解决
问题描述
我正在尝试OutOfMemoryException
在我的 Android 应用程序中修复 's,在我想写的 recyclerView 中:
@Override
public void onViewRecycled(final ViewHolder viewHolder) {
Glide.clear(viewHolder.getImageView());
}
但我得到了错误:
错误:找不到符号方法清除(ImageView)
我在用:
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
解决方案
根据方法的文档。clear
/**
* Cancel any pending loads Glide may have for the view and free any resources that may have been
* loaded for the view.
*
* <p> Note that this will only work if {@link View#setTag(Object)} is not called on this view
* outside of Glide. </p>
*
* @param view The view to cancel loads and free resources for.
* @throws IllegalArgumentException if an object other than Glide's metadata is put as the view's
* tag.
* @see #clear(Target)
*/
public void clear(@NonNull View view) {
clear(new ClearTarget(view));
}
因此,您OutOfMemoryException
将通过明确的方法处理。
并稍微更改您的代码,将上下文传递给 Glide :
Glide.with(viewHolder.getImageView().getContext()).clear(viewHolder.getImageView());
推荐阅读
- php - 在另一个 Dockerfile 中安装 MSSQL
- sqlite - 给出每个项目到特定项目的坐标距离
- javascript - 使用 jquery.html() 函数将文本分配给 div 时,如何在 div 内显示多行文本
- html - 图像适合 flex 行中列的高度
- android - android.view.InflateException: Binary XML file line #10: Error inflating class android.webkit.WebView
- excel - 使用 IF/Right 的 Excel 条件格式函数语法
- database - 涉及数据库的单元测试(插入/更新/选择)
- java - 排除应用程序 Java 错误的原因
- sql - 选择所有对话和每个对话的最后一条消息(+ 用户数据)
- python - Django 在 view.py 中管理同一页面中的不同表单