android让图片等比例缩放
2017-01-13 16:38
337 查看
android中,很多时候需要将图片的宽度设置为屏幕宽度,然后让高度等比例缩放。我自己写了一下,效果是想要的那样,所以记下来分享给大家。
关于怎样测量控件的宽高,可以参考博客http://blog.csdn.net/shirly_yy/article/details/53535438
ImageView imageView = new ImageView(this); imageView.setImageResource(R.drawable.img); //资源文件中的一张图片 WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); int width = wm.getDefaultDisplay().getWidth(); //获取屏幕的宽度 imageView.measure(0,0); //这一步很重要 int height = imageView.getMeasuredHeight() * width / imageView.getMeasuredWidth(); //这里就是将高度等比例缩放,其中imageView.getMeasuredHeight()和imageView.getMeasuredWidth()是计算图片本身的宽高 imageView.setLayoutParams(new ViewGroup.LayoutParams(width, height));
关于怎样测量控件的宽高,可以参考博客http://blog.csdn.net/shirly_yy/article/details/53535438
相关文章推荐
- Android imageView图片按比例缩放
- Android imageView图片按比例缩放
- Android imageView图片按比例缩放
- android项目 之 记事本(12) ----- 图片的等比例缩放及给图片加入边框
- Android imageView图片按比例缩放
- Android imageView图片按比例缩放
- Android开发之imageView图片按比例缩放的实现方法
- Android ImageView图片代码实现按屏幕宽度等比例缩放
- Android ImageView(scaleType属性)图片按比例缩放
- android图片等比例缩放 填充屏幕
- Android imageView图片按比例缩放
- android 加载大图片时计算图片的缩放比例
- android开发布局文件imageview 图片等比例缩放:
- Android imageView图片按比例缩放
- android等比例缩放图片
- Android ImageView(scaleType属性)图片按比例缩放
- android项目 之 记事本(12) ----- 图片的等比例缩放及给图片添加边框
- android图片大小按比例缩放
- Android 详解实现TextView加载带图片标签的Html并按比例缩放
- Android 让图片等比例缩放的三种方法