Android中的ImageView的一些有用的属性

来源:互联网 发布:求平年闰年的简便算法 编辑:程序博客网 时间:2024/06/05 16:41

       ImageView控件中有一个android:scaleType属性。ImageView.setScaleType(ImageView.ScaleType)Sdk中介绍作用为:Options for scaling the bounds of an imageto the bounds of this view.大体意思为:一些缩放边界来控制图片视图的界限范围的选项说白了,就是控制ImageView的边界显示方式.

 

CENTER

Center the image in the view, butperform no scaling.

按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示.

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 thecorresponding dimension of the view (minus padding).

按比例扩大图片的size居中显示,使得图片长()等于或大于View的长()

 

CENTER_INSIDE

Scale the image uniformly (maintain theimage's aspect ratio) so that both dimensions(width and height) of the image will be equal toor less than the corresponding dimension of the view(minus padding).

将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/

 

FIT_CENTER

Scale the image using CENTER.

把图片按比例扩大/缩小到View的宽度,居中显示

 

FIT_END

Scale the image usingEND.

把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置

 

FIT_START

Scale the image using START.

把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置

 

FIT_XY

Scale the image using FILL.

把图片不按比例扩大/缩小到View的大小显示

 

MATRIX

Scaleusing the image matrixwhen drawing.

用矩阵来绘制


例如:
如果获取到的图片的长宽比例是固定的,假设1:1.
设计要去在480*800的分辨率上要显示大小为60*60
那对于的属性就设置为:

android:layout_width="40dip"

android:layout_height="40dip"

android:scaleType="fitXY"

这样,只要你获取到的图片的比例是1:1,无论图片多大,他都会按照60*60的大小来显示。
60px480*800下为40dip(60 -0.5) / 1.5=…)

这样就不需要单独写一个工具来缩放图片了,而且在多分辨率适配的时候,适应能力也大大加强了。

转载自百度:http://wenku.baidu.com/view/8366a9de195f312b3169a586.html

原创粉丝点击