继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

如何设置图片高度固定,宽度可以根据比例缩放

nickcau
关注TA
已关注
手记 113
粉丝 6508
获赞 303

https://img1.mukewang.com/5cc1747f0001cff606101046.jpg

效果图是这样的,我们的思路是拿fresco来加载这个图片

ChatFrescoUtil.displayImage(bean.image, mVoteImage, new BaseControllerListener<ImageInfo>() {
    @Override
    public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
        int height = (int)context.getResources().getDimension(R.dimen.chat_question_info_image_height);
        int scaleWidth =  (int)imageInfo.getWidth()*height/imageInfo.getHeight();
        mVoteImage.setAspectRatio(imageInfo.getWidth()/imageInfo.getHeight());
        adjustSdv(mVoteImage, scaleWidth, height);
    }

    @Override
    public void onFailure(String id, Throwable throwable) {
    }
});
private void adjustSdv(SimpleDraweeView image, int width, int height) {

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) image.getLayoutParams();
    params.width = width;
    params.height = height;
    image.setLayoutParams(params);
}

图片的xml:

<com.facebook.drawee.view.SimpleDraweeView
    android:id="@+id/iv_content"
    android:layout_width="wrap_content"
    android:layout_height="150dip"
    android:layout_below="@+id/tv_content"
    android:layout_marginLeft="@dimen/dp16"
    android:layout_marginTop="12dp"
    tools:src="@color/chat_color_aaaaaa" />

思路是先把这个图片加载出来,然后获取图片的宽高,然后设置图片的缩放比例,然后计算图片缩放后的宽度

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP