android ImageView.ScaleType

android中由于图片素材尺寸和ImageView尺寸不一致,可以通过ScaleType设置不同的图片显示效果。

0、ImageView.ScaleType.MATRIX

/**
 * Scale using the image matrix when drawing. The image matrix can be set using
 * {@link ImageView#setImageMatrix(Matrix)}. From XML, use this syntax:
 * <code>android:scaleType="matrix"</code>.
 */

使用矩阵缩放图片

1、ImageView.ScaleType.FIT_XY

/**

* Scale the image using {@link Matrix.ScaleToFit#FILL}.

* From XML, use this syntax: <code>android:scaleType="fitXY"</code>.

*/

图片铺满屏幕,非等比例缩放图片宽高

2、ImageView.ScaleType.FIT_START

/**

* Scale the image using {@link Matrix.ScaleToFit#START}.

* From XML, use this syntax: <code>android:scaleType="fitStart"</code>.

*/

等比例缩放图像,居上或居左显示在ImageView上,缩放比例按照图片长边和ImageView长边的比值,保证显示图片全部内容

3、ImageView.ScaleType.FIT_CENTER

/**

* Scale the image using {@link Matrix.ScaleToFit#CENTER}.

* From XML, use this syntax:

* <code>android:scaleType="fitCenter"</code>.

*/

ImageView的默认状态,等比例缩放图像,居中显示在ImageView上,缩放比例按照图片长边和ImageView长边的比值,保证显示图片全部内容

4、ImageView.ScaleType.FIT_END

/**

* Scale the image using {@link Matrix.ScaleToFit#END}.

* From XML, use this syntax: <code>android:scaleType="fitEnd"</code>.

*/

等比例缩放图像,居下或居右显示在ImageView上,缩放比例按照图片长边和ImageView长边的比值,保证显示图片全部内容

5、ImageView.ScaleType.CENTER

/**

* Center the image in the view, but perform no scaling.

* From XML, use this syntax: <code>android:scaleType="center"</code>.

*/

图片居中显示,不缩放,当图片图片尺寸超过ImageView尺寸则显示图片的中间部分内容;当图片尺寸小于ImageView尺寸则图片全部内容居中显示在图片上。

6、ImageView.ScaleType.CENTER_CROP

/**

* Scale the image uniformly (maintain the image's aspect ratio) so

* that both dimensions (width and height) of the image will be equal

* to or larger than the corresponding dimension of the view

* (minus padding). The image is then centered in the view.

* From XML, use this syntax: <code>android:scaleType="centerCrop"</code>.

*/

图片居中显示,等比例缩放,使得图片长宽大于ImageView的宽高(即将图片短边缩放到与ImageView边一致,同时按照相同比例缩放长边),图片超出的部分剪裁掉。

7、ImageView.ScaleType.CENTER_INSIDE

/**

* Scale the image uniformly (maintain the image's aspect ratio) so

* that both dimensions (width and height) of the image will be equal

* to or less than the corresponding dimension of the view

* (minus padding). The image is then centered in the view.

* From XML, use this syntax: <code>android:scaleType="centerInside"</code>.

*/

图片居中显示,等比例缩放,使得图片长宽小于或等于ImageView的宽高,当图片图片尺寸超过ImageView尺寸则等比例缩小图片尺寸到ImageView尺寸;当图片尺寸小于ImageView尺寸居中显示

猜你喜欢

转载自blog.csdn.net/u013795543/article/details/82286737
今日推荐