JuliaAilse 发表于 2013-1-14 18:03:10

【android】scaleType属性与ImagView中图片的显示的关系

      关于android中ImageView的外观,即图片在其内显示出的样子,与布局文件中adjustViewBonds和scaleType
属性的关系。我进行了一些探索。现跟大家共享,欢迎各位指教。分别将adjustViewBonds设为true和false,与各种scaleType搭配,产生了不同效果。(上面的ImagView的adjstViewBonds值为false;下面的ImagView的adjstViewBonds值为true;两个ImagView大小相同)如下:
代码:
<ImageView      android:id="@+id/imageView1"      android:layout_width="fill_parent"      android:layout_height="200dip"      android:adjustViewBounds="false"      android:scaleType="centerInside"//此处每次更改      android:src="@drawable/ic_3" />//此处两幅图间更改,一副图的大小较小,另一幅的较大。    <ImageView      android:id="@+id/imageView2"      android:layout_width="fill_parent"      android:layout_height="200dip"      android:adjustViewBounds="true"      android:scaleType="centerInside"//此处每次更改      android:src="@drawable/ic_3" />//此处两幅图间更改,一副图的大小较小,另一幅的较大。 原图:

http://dl.iteye.com/upload/attachment/0063/3485/5ec0a6be-9794-340f-973f-897c26ddb00f.gif
http://dl.iteye.com/upload/attachment/0063/3487/c614e7fa-7ea3-39e2-8001-436f3de9de26.jpg
 

1、scaleType=“matrix”
如图pic1、pic2.
是保持原图大小、从左上角的点开始,以矩阵形式绘图。

http://dl.iteye.com/upload/attachment/0063/3489/4563ab80-6d91-3a15-8fde-2f4ed02dc69b.png
 
pic1
 
http://dl.iteye.com/upload/attachment/0063/3491/b5bd405e-74f1-3180-8a54-d7b2b9400102.png
pic2
 
2、scaleType=“fitXY”
如图pic3、pic4.
是将原图进行横方向(即XY方向)的拉伸后绘制的。

http://dl.iteye.com/upload/attachment/0063/3493/1d152b46-b876-3979-87da-fd6c34ff6e35.png
pic3
 
http://dl.iteye.com/upload/attachment/0063/3495/10901cf7-c601-3e73-b73d-07f6d651b5b7.png
pic4
 
3、scaleType=“fitStart”
如图pic5、pic6。
是将原图沿左上角的点(即matrix方式绘图开始的点),按比例缩放原图绘制而成的。

http://dl.iteye.com/upload/attachment/0063/3497/17ac7fa1-641c-3b1f-a5bb-fdfa9c131182.png
pic5
 
http://dl.iteye.com/upload/attachment/0063/3499/689b6640-ff87-3e8e-a280-d77d1e0bfb5d.png
pic6
 
4、scaleType=“fitCenter”
如图pic7、pic8。
是将原图沿上方居中的点(即matrix方式绘图第一行的居中的点),按比例缩放原图绘制而成的。

http://dl.iteye.com/upload/attachment/0063/3501/1420dd69-1155-3966-8a84-8115db03fc5a.png
pic7
 
http://dl.iteye.com/upload/attachment/0063/3503/e73ce939-6d2a-3806-a0e1-72c452c71909.jpg
pic8
 
5、scaleType=“fitEnd”
如图pic9、pic10。、
是将原图沿下方居中的点(即matrix方式绘图最后一行的居中的点),按比例缩放原图绘制而成的。

http://dl.iteye.com/upload/attachment/0063/3505/b543a21d-41ba-3be2-b2ad-d10adeea1d91.png
pic9
 
http://dl.iteye.com/upload/attachment/0063/3507/c256d519-5615-3c1b-b972-e4d21746c543.png
pic10
 
6、scaleType=“Center”
如图pic11、pic12。
是保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像。

http://dl.iteye.com/upload/attachment/0063/3509/87fbcda8-b6a6-3302-9fef-6dea0efd87a2.png
pic11
 
http://dl.iteye.com/upload/attachment/0063/3511/2e1c2a0d-0ebb-3995-8daf-0d789e534f2a.pngpic12
 
7、scaleType=“centerCrop”
如图pic13、pic14。
不保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像(以填满
ImagView为目标,对原图进行裁剪)。

http://dl.iteye.com/upload/attachment/0063/3513/c49ab572-e827-3baf-a705-40d903aa98fe.png
pic13
 
http://dl.iteye.com/upload/attachment/0063/3515/bd8a82d3-6676-3b8e-9508-f94885d25f4a.png
pic14
 
8、scaleType=“centerInside”
如图pic15、pic16.
不保持原图大小,以原图的几何中心点和ImagView的几何中心点为基准,只绘制ImagView大小的图像(以显示
完整图片为目标,对原图进行缩放)。

http://dl.iteye.com/upload/attachment/0063/3517/1181d059-8f09-33ae-abfe-e64113c074d0.png
pic15
 
http://dl.iteye.com/upload/attachment/0063/3519/dc2a7ef4-5f2f-3f05-bc9e-ea54f68d6e41.png
pic16

      (事实证明,adjustViewBonds单独设置无影响。)

      依本人之见,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大小的图像,不同的是是否保持原图大小和绘图的目标不同、采取的手段不同。
页: [1]
查看完整版本: 【android】scaleType属性与ImagView中图片的显示的关系