Android的ImageView如何maxHeight与maxWidth生效

来源:互联网 发布:淘宝不锈钢三角尺 编辑:程序博客网 时间:2024/04/30 16:01

ImageView有一个属性设置:adjustViewBounds,其值默认为false,

若没有设置成true,则当ImageView的Height/Width设置成wrap_content时,则maxHeight, maxWidth都将不起作用。

正确的设置方法如下:

<ImageView     android:layout_width="match_parent"    android:adjustViewBounds="true"    android:layout_height="wrap_content"    android:maxHeight="250dp"    android:scaleType="fitStart"    android:src="@drawable/test_img"    />

这样,当图片高度大于250dp时,会缩放到250dp的高度。

0 0
原创粉丝点击