网上说的设置fitxy center啥都不适用了,我已经尝试全。只能用最原始的办法来实现这个功能。
首先布局文件就写个imageview,宽高都设置成wrap_content即可,别的属性不需要,接着就是测量绘制工作。
int screenWidth =getScreenWidth(mContext) - ViewUtils.dip2px(mContext, 30); //顶格的宽度
Glide.with(mContext).asBitmap().load(bean).into(new BitmapImageViewTarget(picHolder.image){
@Override
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) {
super.onResourceReady(resource, transition);
//1、使用Glide下载图片转成Bitmap,并获取原始图片的宽高:
width = resource.getWidth();
height = resource.getHeight();
//2、修改宽度为屏幕宽度(一般要减去两边空白距离,此案例左右留白15dp,然后高度等比缩放)
ViewGroup.LayoutParams lp =imageView.getLayoutParams();
lp.height =height *screenWidth/width; //高度等比缩放
lp.width =screenWidth;
imageView.setLayoutParams(lp);
}
});