标签:
/** * 设置图片根据屏幕宽度进行等比例缩放 * @param imageView */ public static void setImageMatchScreenWidth(ImageView imageView){ BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView.getDrawable(); if(bitmapDrawable == null) return; Bitmap bitmap = bitmapDrawable.getBitmap(); if(bitmap == null) return; int defaultWidth = AppUtil.catchDisplayWidth(imageView.getContext()); float scale = (float) defaultWidth / (float) bitmap.getWidth(); int defaultHeight = Math.round(bitmap.getHeight() * scale); LayoutParams params = imageView.getLayoutParams(); params.width = defaultWidth; params.height = defaultHeight; imageView.setLayoutParams(params); }
Android ImageView图片代码实现按屏幕宽度等比例缩放
标签:
原文地址:http://www.cnblogs.com/xiakexinghouzi/p/4741311.html