關(guān)于ImageView對圖像縮放方式的控制,是通過ScaleType,它們分別表示不同的含義:
源碼及說明:
/**
* 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ù)一個3x3的矩陣對其中圖片進行縮放
2.FIT_XY:將圖片非等比例縮放到大小與ImageView相同。
3.FIT_START: 縮放方式同F(xiàn)IT_CENTER腐碱,只是將圖片顯示在左方或上方癌别,而不是居中歼争。
4.FIT_CENTER:ImageView的默認狀態(tài),大圖等比例縮小考抄,使整幅圖能夠居中顯示在ImageView中细疚,小圖等比例放大,同樣要整體居中顯示在ImageView中川梅。
5.FIT_END:縮放方式同F(xiàn)IT_CENTER疯兼,只是將圖片顯示在右方或下方然遏,而不是居中。
6.CENTER:圖片大小為原始大小吧彪,如果圖片大小大于ImageView控件啦鸣,則截取圖片中間部分,若小于来氧,則直接將圖片居中顯示诫给。
7.CENTER_CROP:將圖片等比例縮放,讓圖像的短邊與ImageView的邊長度相同啦扬,即不能留有空白中狂,縮放后截取中間部分進行顯示。
8.CENTER_INSIDE:將圖片大小大于ImageView的圖片進行等比例縮小扑毡,直到整幅圖能夠居中顯示在ImageView中胃榕,小于ImageView的圖片不變,直接居中顯示瞄摊。