ImageView的android:scaleType属性
首先看一下android developers中的解释:“Options for scaling the bounds of an image to the bounds of this view.”即,缩放图片这个视图边界的选项。
具体属性如下:
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 usingCENTER. |
ImageView.ScaleType | FIT_END | Scale the image usingEND. |
ImageView.ScaleType | FIT_START | Scale the image usingSTART. |
ImageView.ScaleType | FIT_XY | Scale the image usingFILL. |
ImageView.ScaleType | MATRIX | Scale using the image matrix when drawing. |
详尽的用法如下:
Enum Values
public static finalImageView.ScaleTypeCENTER
Added in API level 1Center the image in the view, but perform no scaling. From XML, use this syntax:android:scaleType="center".
public static finalImageView.ScaleType CENTER_CROP Added in API level 1Scale 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".
public static finalImageView.ScaleTypeCENTER_INSIDE
Added in API level 1Scale 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".
public static finalImageView.ScaleTypeFIT_CENTER
Added in API level 1Scale the image usingCENTER. From XML, use this syntax:android:scaleType="fitCenter".
public static finalImageView.ScaleTypeFIT_END
Added in API level 1Scale the image usingEND. From XML, use this syntax:android:scaleType="fitEnd".
public static finalImageView.ScaleTypeFIT_START
Added in API level 1Scale the image usingSTART. From XML, use this syntax:android:scaleType="fitStart".
public static finalImageView.ScaleTypeFIT_XY
Added in API level 1Scale the image usingFILL. From XML, use this syntax:android:scaleType="fitXY".
public static finalImageView.ScaleTypeMATRIX
Added in API level 1Scale using the image matrix when drawing. The image matrix can be set usingsetImageMatrix(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来绘制。
scaletype的种类分为三类matrix(默认)、fit-X类、和center类。matrix就不多说。fit-X类中,
fitStart、fitCenter和fitEnd之间的都是根据需要使原图改变对ImgView进行适应,不剪裁,按matrix进行绘制,但它们的区别在于基准不同。fitStart的基准为最上角的点(即matrix方式开始的点)fitCenter的基准点为中间的点(matrix方式中可以使图片居中的点),而fitEnd的基准点为右下角的点(即matrix方式最后绘制点)。center类中,center、centerCrop、centerInside都是以原图的几何中心点和ImagView的几何中心点为基准,且只绘制ImagView大小的图像,不同的是是否保持原图大小和绘图的目标不同、采取的手段不同。
更多相关文章
- android操作sqlite3的blob字段,显示数据中的图片
- android 获取SD卡的图片及其路径
- Android:读取本地相册与相机获取图片上传到服务器(用字符串的形式
- Android 图片缩放与旋转的实现详解
- 图片的放大缩小
- 关于android 调用系统图片浏览器并返回图片路径问题
- Android保存图片到本地
- 【Android自学笔记】Android获取手机和存储卡上的图片
- android中如何显示图片的一部分