Android ImageView图片代码实现按屏幕宽度等比例缩放

 /**
	 * 设置图片根据屏幕宽度进行等比例缩放
	 * @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);
	}

  

posted @ 2015-08-19 09:38  侠客行猴子  阅读(2706)  评论(0编辑  收藏  举报