ImageView的android:scaleType屬性

     首先看一下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

public static final ImageView.ScaleType CENTER

Added in  API level 1

Center the image in the view, but perform no scaling. From XML, use this syntax: android:scaleType="center". ui

public static final ImageView.ScaleType  CENTER_CROP
Added in  API level 1

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

public static final ImageView.ScaleType CENTER_INSIDE

Added in  API level 1

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

public static final ImageView.ScaleType FIT_CENTER

Added in  API level 1

Scale the image using CENTER. From XML, use this syntax: android:scaleType="fitCenter". orm

public static final ImageView.ScaleType FIT_END

Added in  API level 1

Scale the image using END. From XML, use this syntax: android:scaleType="fitEnd". htm

public static final ImageView.ScaleType FIT_START

Added in  API level 1

Scale the image using START. From XML, use this syntax: android:scaleType="fitStart". 圖片

public static final ImageView.ScaleType FIT_XY

Added in  API level 1

Scale the image using FILL. From XML, use this syntax: android:scaleType="fitXY".

public static final ImageView.ScaleType MATRIX

Added in  API level 1

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來繪製。


      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大小的圖像,不一樣的是是否保持原圖大小和繪圖的目標不一樣、採起的手段不一樣。

相關文章
相關標籤/搜索