首先看一下android developers中的解释:“Options for scaling the bounds of an image to the bounds of this view.”即,缩放图片这个视图边界的选项。 html
具体属性以下: android
Enum Values | ||
---|---|---|
ImageView.ScaleType | CENTER | Center the image in the view, but perform no scaling. |
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). |
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). |
ImageView.ScaleType | FIT_CENTER | Scale the image using CENTER. |
ImageView.ScaleType | FIT_END | Scale the image using END. |
ImageView.ScaleType | FIT_START | Scale the image using START. |
ImageView.ScaleType | FIT_XY | Scale the image using FILL. |
ImageView.ScaleType | MATRIX | Scale using the image matrix when drawing. |
详尽的用法以下: less
Enum Values ide
Center the image in the view, but perform no scaling. From XML, use this syntax: android:scaleType="center". ui
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:android:scaleType="centerCrop". this
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:android:scaleType="centerInside". spa
Scale the image using CENTER. From XML, use this syntax: android:scaleType="fitCenter". orm
Scale the image using END. From XML, use this syntax: android:scaleType="fitEnd". htm
Scale the image using START. From XML, use this syntax: android:scaleType="fitStart". 图片
Scale the image using FILL. From XML, use this syntax: android:scaleType="fitXY".
Scale using the image matrix when drawing. The image matrix can be set using setImageMatrix(Matrix). From XML, use this syntax:android:scaleType="matrix".
即: ImageView.ScaleType.CENTER|android:scaleType="center" 表示图片在ImageView这个视图的中间,可是不对图片进行缩放,详细解释为,以原图的几何中心点和ImagView的几何中心点为基准,按图片的原来size居中显示,不缩放,当图片长/宽超过View的长/宽,则截取图片的居中部分显示ImageView的size.当图片小于View 的长宽时,只显示图片的size,不剪裁;
ImageView.ScaleType.CENTER_CROP|android:scaleType="centerCrop"表示均匀地缩放图像(保持图像的纵横比),以使图像的两个尺寸(宽度和高度)将等于或大于视图(减去填充)的相应尺寸,详细解释为,以原图的几何中心点和ImagView的几何中心点为基准,按比例扩大(图片小于View的宽时)图片的size居中显示,使得图片长 (宽)等于或大于View的长(宽),并按View的大小截取图片。当原图的size大于ImageView时,按比例缩小图片,使得长宽中有一贯等于ImageView,另外一向大于ImageView。实际上,使得原图的size大于等于ImageView;
ImageView.ScaleType.CENTER_INSIDE|android:scaleType="centerInside" 表示均匀地缩放图像(保持图像的纵横比),以使图像的两个尺寸(宽度和高度)将等于或小于视图(减去填充)的相应尺寸,详细解释为,以原图的几何中心点和ImagView的几何中心点为基准,将图片的内容完整居中显示,经过按比例缩小原来的size使得图片长(宽)等于或小于ImageView的长(宽);
ImageView.ScaleType.FIT_CENTER|android:scaleType="fitCenter"表示把图片按比例扩大(缩小)到View的宽度,居中显示;
ImageView.ScaleType.FIT_END|android:scaleType="fitEnd"表示把图片按比例扩大(缩小)到View的宽度,在view的下部分部显示;
ImageView.ScaleType.FIT_START|android:scaleType="fitStart"表示把图片按比例扩大(缩小)到view的宽度,在view的上部分显示;
ImageView.ScaleType.FIT_XY|android:scaleType="fitXY"表示把图片按照指定的大小在View中显示,拉伸显示图片,不保持原比例,填满View;
ImageView.ScaleType.MATRIX|android:scaleType="matrix"表示用matrix来绘制。
fitStart、fitCenter和fitEnd之间的都是根据须要使原图改变对ImgView进行适应,不剪裁,按matrix进行绘制,但它们的区别在于基准不一样。fitStart的基准为最上角的点(即matrix方式开始的点)fitCenter的基准点为中间的点(matrix方式中能够使图片居中的点),而fitEnd的基准点为右下角的点(即matrix方式最后绘制点)。center类中,center、centerCrop、centerInside都是以原图的几何中心点和ImagView的几何中心点为基准,且只绘制ImagView大小的图像,不一样的是是否保持原图大小和绘图的目标不一样、采起的手段不一样。