服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Android - ImageView的属性android:scaleType的作用分析

ImageView的属性android:scaleType的作用分析

2021-01-28 15:35Android开发网 Android

本篇文章是对ImageView的属性android:scaleType的作用进行了详细的分析介绍,需要的朋友参考下

在网上查了好多资料,大致都雷同,大家都是互相抄袭的,看着很费劲,不好理解,自己总结一下,留着需要看的话来查找。
代码中的例子如下:

复制代码 代码如下:

<imageview
            android:id="@+id/iv_bit_1"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />
        <imageview
            android:id="@+id/iv_bit_2"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />
        <imageview
            android:id="@+id/iv_bit_3"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />
        <imageview
            android:id="@+id/iv_bit_4"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />
        <imageview
            android:id="@+id/iv_bit_5"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />
        <imageview
            android:id="@+id/iv_bit_6"
            android:layout_width="@dimen/passcode_width"
            android:layout_height="@dimen/passcode_height"
            android:scaletype="fitxy" />


通过api的查询得知,
imageview.scaletype的结构为:

 

继承关系
public static final enum imageview.scaletype extends enum<e extends enum<e>>
java.lang.object
java.lang.enum<e extends java.lang.enum<e>>
android.widget.imageview.scaletype

类概述
将图片边界缩放,以适应视图边界时的可选项。

常量
public static final imageview.scaletype center
在视图中使图像居中,不执行缩放。 在 xml 中可以使用的语法: android:scaletype="center"。
public static final imageview.scaletype center_crop
均衡的缩放图像(保持图像原始比例),使图片的两个坐标(宽、高)都大于等于 相应的视图坐标(负的内边距)。图像则位于视图的中央。 在 xml 中可以使用的语法:android:scaletype="centercrop"。
public static final imageview.scaletype center_inside
均衡的缩放图像(保持图像原始比例),使图片的两个坐标(宽、高)都小于等于 相应的视图坐标(负的内边距)。图像则位于视图的中央。 在 xml 中可以使用的语法:android:scaletype="centerinside"。
public static final imageview.scaletype fit_center
使用 center 方式缩放图像。 在 xml 中可以使用的语法: android:scaletype="fitcenter"。
public static final imageview.scaletype fit_end
使用 end 方式缩放图像。 在 xml 中可以使用的语法: android:scaletype="fitend"。
public static final imageview.scaletype fit_start
使用 start 方式缩放图像。 在 xml 中可以使用的语法:android:scaletype="fitstart"。
public static final imageview.scaletype fit_xy
使用 fill 方式缩放图像。 在 xml 中可以使用的语法: android:scaletype="fitxy"。
public static final imageview.scaletype matrix
绘制时,使用图像矩阵方式缩放。图像矩阵可以通过 setimagematrix(matrix) 设置。在 xml 中可以使用的语法: android:scaletype="matrix"。
用代码展示着几个属性的效果,效果截图:
主界面:

 

ImageView的属性android:scaleType的作用分析

center效果:

ImageView的属性android:scaleType的作用分析

center_crop效果:

ImageView的属性android:scaleType的作用分析

center_inside效果:

ImageView的属性android:scaleType的作用分析

fit_center效果:

ImageView的属性android:scaleType的作用分析

fit_start效果:

ImageView的属性android:scaleType的作用分析

fit_end效果:

ImageView的属性android:scaleType的作用分析

fit_xy效果:

ImageView的属性android:scaleType的作用分析

matrix效果:

ImageView的属性android:scaleType的作用分析

结果分析:
我选取的原始图片明显标志如下:左上角有蝴蝶、花朵,右下角为一个蝗虫,且图片像素大于 320×480,各种类型的差异通过查看图片的明显标志即可窥见一斑。比如fit_start,填充于屏幕上方,并等比例缩放;相反,fit_end置于屏幕下方,而fit_center则在中间。center_crop裁剪了图片的中间部分填充屏幕。其它类型可自行查看分析。

延伸 · 阅读

精彩推荐