美文网首页Android深入
Fresco SimpleDraweeView 图片高度自适应

Fresco SimpleDraweeView 图片高度自适应

作者: robert_xu | 来源:发表于2017-04-21 14:27 被阅读0次

    /**

    * 通过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);

    }

    相关文章

      网友评论

        本文标题:Fresco SimpleDraweeView 图片高度自适应

        本文链接:https://www.haomeiwen.com/subject/zyydzttx.html