Android ImageView宽度被压缩后自动压缩高度

在Android开发中,经常会遇到ImageView的大小和图片本身的大小不一样,不过本文并不是解决图片显示到ImageView缩放和解决OOM,而是解决当图片宽度被压缩后,图片的高度没有跟着压缩,而是图片本身有多高,ImageView就有多高的状态,上下会有空白,影响布局的状态

下面是问题截图

![问题截图](http://image.raye.wang/device-2015-11-04-130911.png)
造成这种问题的原因很简单,因为ImageView的布局的高度是wrap_content,但是为了做瀑布流效果,所以不能固定ImageView的高度。解决办法也很简单,其实查查API文档就会发现有个属性是专门解决这个问题的(我当时百度了好久。。因为很少看API文档)

在xml布局中加入

COPY
1
android:adjustViewBounds="true"

加入后,运行效果如下:

另外本demo的git地址为
http://git.oschina.net/raywang2014/AndroidViewDemo
里面有我平时写的一些小demo,大家有兴趣可以去看看

Authorship: 作者
Article Link: https://raye.wang/2015/12/11/Android-ImageView%E5%AE%BD%E5%BA%A6%E8%A2%AB%E5%8E%8B%E7%BC%A9%E5%90%8E%E8%87%AA%E5%8A%A8%E5%8E%8B%E7%BC%A9%E9%AB%98%E5%BA%A6/
Copyright: All posts on this blog are licensed under the CC BY-NC-SA 4.0 license unless otherwise stated. Please cite Raye Blog !