图片显示不变形

xiaoxiao2021-02-28  172

ImageView我们是经常使用的控件,对于它的属性和设置早已熟烂于心,但是有时候还是会碰到一些问题,比如:变形问题,

一般解决方法是使用centerCrop,fitCenter,fitXY等属性,但是有时候需求是图片宽度match空间,且不知道空间的大小,保证不变形,也不能放大缩小图片(fitCenter,centerCrop会导致),那我们就是用fitXY,但是拉伸会变形,(有人使用矩阵图解决,想复杂了),这时候被我们忽略的属性就至关重要了,android:adjustViewBounds

ImageViewandroid:adjustViewBounds属性为是否保持原图的长宽比,单独设置不起作用,需要配合maxWidthmaxHeight一起使用。 <ImageView android:id="@+id/imageView3" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitXY" android:src="@mipmap/img_contacts_tips" />

转载请注明原文地址: https://www.6miu.com/read-33051.html

最新回复(0)