问题描述
我刚刚迁移到Fresco
库,用于在应用程序中加载图像.
I have just migrated to the Fresco
library for loading images in my app.
我需要收听图像加载事件,当然,我在文档收听事件下载
I need to listen to Image Loading Events, of course I read this article in documentation Listening to download events
这正是我所需要的,但是....有几件事我不喜欢.
This is exactly what I need, but....There few things that I don't like.
我的目标是隐藏View
,如果它无法从网上下载.
My goal is to hide View
if it fails to download it from the net.
-
即使在回调方法上,我也无法从控制器引用
SimpleDraweeView
.我需要隐藏View
,但似乎无法获得对其的引用.
I cannot reference
SimpleDraweeView
from controller, even on callback method. I need to hideView
, but it seems that I cannot get reference to it.
每次需要加载图像时,都需要使用Builder
创建控制器的对象,并且在将这种方法与包含图像的大量物品一起使用时,这可能会导致性能问题.
Each time I need to load image, I need to create object of controller using Builder
, and this can cause performance issues when using this approach with list of a lot of items with images.
holder.simpleDraweeViewImage.setController(Fresco.newDraweeControllerBuilder() .setControllerListener(controllerListener) .setUri(currentItem.getImage()) .build());
holder.simpleDraweeViewImage.setController(Fresco.newDraweeControllerBuilder() .setControllerListener(controllerListener) .setUri(currentItem.getImage()) .build());
我需要能够从控制器中引用SimpleDraweeView
,并且在MVC
模式方法中,如果控制器知道视图,就可以了.
I need to able to have reference to the SimpleDraweeView
from controller, and in MVC
pattern approach it seems okay if controller is aware about view.
请提出实现我的目标的最佳方法.
Please suggest the best way to rich my goal.
谢谢.
推荐答案
可以在onFailure方法上隐藏:
Can hide on onFailure method:
ControllerListener listener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
//Action on final image load
}
@Override
public void onFailure(String id, Throwable throwable) {
//Action on failure
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setControllerListener(listener)
.build();
draweeView.setController(controller);
这篇关于壁画图像加载回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!