效果图是这样的,我们的思路是拿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" />
思路是先把这个图片加载出来,然后获取图片的宽高,然后设置图片的缩放比例,然后计算图片缩放后的宽度