gpt4 book ai didi

android - Glideclear()方法无法解决

转载 作者:行者123 更新时间:2023-12-02 17:51:30 25 4
gpt4 key购买 nike

我正在尝试修复 Android 应用程序中的 OutOfMemoryException,在我的 recyclerView 中我想写入:

@Override
public void onViewRecycled(final ViewHolder viewHolder) {
Glide.clear(viewHolder.getImageView());
}

但我收到错误:

error: cannot find symbol method clear(ImageView)

我正在使用:

implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'

最佳答案

根据documentation对于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将通过clear方法处理。

稍微改变你的代码,将上下文传递给 Glide :

Glide.with(viewHolder.getImageView().getContext()).clear(viewHolder.getImageView());

关于android - Glideclear()方法无法解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50088982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com