Android ImageView图片宽度为控件宽度,高度按比例缩放
实现方式
在Java代码里面实现
首先,定义ImageView,在该ImageView中,我们需要设置属性android:adjustViewBounds=”true”,他的意思图片是否保持宽高比。切记的一点是该属性需要与maxWidth、MaxHeight一起使用,否则单独使用没有效果。
1 | <ImageView |
刚刚说了,android:adjustViewBounds=”true”必须与MaxHeight一起使用才能有效,所以,我要设置该ImageView的最大高度MaxHeight:
1 | int screenWidth = getScreenWidth(this); // 获取屏幕宽度a |
在Xml中实现
1 | <ImageView |