/**
* 通过imageWidth 的宽度,自动适应高度
*
*@paramsimpleDraweeViewview
*@paramimagePathUri
*@paramimageWidthwidth
*@parammContextcontext
*/
public static voidloadUrlAdaptiveHeight(finalSimpleDraweeView simpleDraweeView, String imagePath,final intimageWidth, Context mContext) {
finalViewGroup.LayoutParams layoutParams = simpleDraweeView.getLayoutParams();
ControllerListener controllerListener =newBaseControllerListener() {
@Override
public voidonFinalImageSet(String id,@NullableImageInfo imageInfo,@NullableAnimatable anim) {
if(imageInfo ==null) {
return;
}
intheight = imageInfo.getHeight();
intwidth = imageInfo.getWidth();
layoutParams.width=imageWidth;
layoutParams.height= (int) ((float) (imageWidth* height) / (float) width);
simpleDraweeView.setLayoutParams(layoutParams);
}
@Override
public voidonIntermediateImageSet(String id,@NullableImageInfo imageInfo) {
Log.d("TAG","Intermediate image received");
}
@Override
public voidonFailure(String id, Throwable throwable) {
throwable.printStackTrace();
}
};
DraweeController controller = Fresco.newDraweeControllerBuilder().setControllerListener(controllerListener).setUri(Uri.parse(imagePath)).build();
simpleDraweeView.setController(controller);
}