Uri uri = Uri.parse(“xxx”);
PipelineDraweeControllerBuilder sdcb = Fresco.newDraweeControllerBuilder();
sdcb.setUri(uri);
//加载失败之后,点击提示重新加载的图片资源重新加载
sdcb.setTapToRetryEnabled(true);
//图片下载完之后自动播放动画
sdcb.setAutoPlayAnimations(true);
//在指定一个新的controller的时候,使用setOldController,这可节省不必要的内存分配。
sdcb.setOldController(simpleDraweeView.getController());
ControllerListener listener =new BaseControllerListener(){
@Override
public void onSubmit(String id, Object callerContext) {
//提交请求之前调用的方法
Log.d("", "onSubmit: " + id);
}
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
// 所有图片都加载成功时触发的方法
Log.d("", "onFinalImageSet: " + id);
Toast.makeText(mContext,"加载图片成功",Toast.LENGTH_SHORT).show();
}
@Override
public void onIntermediateImageSet(String id, ImageInfo imageInfo) {
//当中间图片下载成功的时候触发,用于多图请求
}
@Override
public void onIntermediateImageFailed(String id, Throwable throwable) {
//当中间图片下载失败的时候触发,用于多图请求
}
@Override
public void onFailure(String id, Throwable throwable) {
// 加载图片失败时回调的方法
Log.d("加载图片失败", "onFailure: " + id);
Toast.makeText(mContext,"加载图片失败",Toast.LENGTH_SHORT).show();
}
@Override
public void onRelease(String id) {
//释放图片资源时加载的方法
Log.d("", "onRelease: " + id);
}
};
sdcb.setControllerListener(listener);
DraweeController controller = sdcb.build();
GenericDraweeHierarchyBuilder builder =
new GenericDraweeHierarchyBuilder(getResources());
GenericDraweeHierarchy hierarchy = builder
.setFadeDuration(300)
.setProgressBarImage(new ProgressBarDrawable())//进度展示
.build();
simpleDraweeView.setHierarchy(hierarchy);
simpleDraweeView.setController(controller);