需求
在DraweeView加载图片失败的时候显示同一个布局上的按钮,点击按钮可让DraweeView重新加载。
问题,失败的时候显示了按钮,但是点击了按钮后就没有了反应,代码如下:
private void showDraweeView(PhotoDraweeView view, String url) {
Uri uri = Uri.parse(url);
if (null == uri) { return; }
ControllerListener listener = new BaseControllerListener<ImageInfo>() {
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
super.onFinalImageSet(id, imageInfo, animatable);
if (imageInfo == null || mPhotoView == null) { return; }
mPhotoView.update(imageInfo.getWidth(), imageInfo.getHeight());
}
public void onFailure(String id, Throwable throwable) {
super.onFailure(id, throwable);
visibleButton(true);
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setControllerListener(listener)
.setTapToRetryEnabled(true)
.build();
view.setController(controller);
GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
.setProgressBarImage(new CustomProgressBar(mContext))
.build();
mPhotoView.setHierarchy(hierarchy);
}
修改后的代码
private void showDraweeView(PhotoDraweeView view, String url) {
GenericDraweeHierarchy hierarchy = new GenericDraweeHierarchyBuilder(mContext.getResources())
.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER)
.setProgressBarImage(new CustomProgressBar(mContext))
.build();
mPhotoView.setHierarchy(hierarchy);
Uri uri = Uri.parse(url);
if (null == uri) { return; }
ControllerListener listener = new BaseControllerListener<ImageInfo>() {
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
super.onFinalImageSet(id, imageInfo, animatable);
if (imageInfo == null || mPhotoView == null) { return; }
mPhotoView.update(imageInfo.getWidth(), imageInfo.getHeight());}
public void onFailure(String id, Throwable throwable) {
super.onFailure(id, throwable);
visibleReloadView(true);
}
};
DraweeController controller =
Fresco.newDraweeControllerBuilder()
.setUri(uri)
.setControllerListener(listener)
.setTapToRetryEnabled(true)
.build();
view.setController(controller);
}
网友评论