關(guān)于ImageView對(duì)圖像縮放方式的控制,是通過(guò)ScaleType,它們分別表示不同的含義:
源碼及說(shuō)明:
/**
* Options for scaling the bounds of an image to the bounds of this view.
*/
public enum ScaleType {
/**
* Scale using the image matrix when drawing. The image matrix can be set using
* {@link ImageView#setImageMatrix(Matrix)}. From XML, use this syntax:
* <code>android:scaleType="matrix"</code>.
*/
MATRIX (0),
/**
* Scale the image using {@link Matrix.ScaleToFit#FILL}.
* From XML, use this syntax: <code>android:scaleType="fitXY"</code>.
*/
FIT_XY (1),
/**
* Scale the image using {@link Matrix.ScaleToFit#START}.
* From XML, use this syntax: <code>android:scaleType="fitStart"</code>.
*/
FIT_START (2),
/**
* Scale the image using {@link Matrix.ScaleToFit#CENTER}.
* From XML, use this syntax:
* <code>android:scaleType="fitCenter"</code>.
*/
FIT_CENTER (3),
/**
* Scale the image using {@link Matrix.ScaleToFit#END}.
* From XML, use this syntax: <code>android:scaleType="fitEnd"</code>.
*/
FIT_END (4),
/**
* Center the image in the view, but perform no scaling.
* From XML, use this syntax: <code>android:scaleType="center"</code>.
*/
CENTER (5),
/**
* 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: <code>android:scaleType="centerCrop"</code>.
*/
CENTER_CROP (6),
/**
* 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: <code>android:scaleType="centerInside"</code>.
*/
CENTER_INSIDE (7);
ScaleType(int ni) {
nativeInt = ni;
}
final int nativeInt;
}
1.MATRIX:根據(jù)一個(gè)3x3的矩陣對(duì)其中圖片進(jìn)行縮放
2.FIT_XY:將圖片非等比例縮放到大小與ImageView相同。
3.FIT_START: 縮放方式同F(xiàn)IT_CENTER,只是將圖片顯示在左方或上方,而不是居中。
4.FIT_CENTER:ImageView的默認(rèn)狀態(tài),大圖等比例縮小,使整幅圖能夠居中顯示在ImageView中,小圖等比例放大,同樣要整體居中顯示在ImageView中。
5.FIT_END:縮放方式同F(xiàn)IT_CENTER,只是將圖片顯示在右方或下方,而不是居中。
6.CENTER:圖片大小為原始大小,如果圖片大小大于ImageView控件,則截取圖片中間部分,若小于,則直接將圖片居中顯示。
7.CENTER_CROP:將圖片等比例縮放,讓圖像的短邊與ImageView的邊長(zhǎng)度相同,即不能留有空白,縮放后截取中間部分進(jìn)行顯示。
8.CENTER_INSIDE:將圖片大小大于ImageView的圖片進(jìn)行等比例縮小,直到整幅圖能夠居中顯示在ImageView中,小于ImageView的圖片不變,直接居中顯示。