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

时间:2015-08-19 10:40:34   收藏:0   阅读:460
 /**
	 * 设置图片根据屏幕宽度进行等比例缩放
	 * @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);
	}

  

原文:http://www.cnblogs.com/xiakexinghouzi/p/4741311.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!