ScaleType and adjustViewBounds attributes of Android ImageView
The scaleType attributes of ImageView include matrix (default), center, centerCrop, centerInside, fitCenter, fitEnd, fitStart, and fitXY.
Android: scaleType = "center"
Keep the source image size in the center of ImageView. When the size of the source image is greater than the size of the ImageView, part of the cropping process is exceeded.
Android: scaleType = "centerCrop"
For the purpose of filling up the entire ImageView, align the center of the source image to the center of the ImageView, and proportionally enlarge the source image until the ImageView is filled up (indicating that the width and height of the ImageView must be filled up ), crop the image that exceeds the ImageView size.
Android: scaleType = "centerInside"
For the purpose of completely displaying the original image, the image content is displayed in the center, and the size width (height) of the original image is reduced proportionally to or less than the width (height) of the ImageView ). If the size of the source image is smaller than the size of the ImageView, the size of the source image is not processed and displayed in the ImageView center.
Android: scaleType = "matrix"
The size of the source image is not changed. The source image is drawn from the upper left corner of the ImageView. The part where the source image exceeds the ImageView is cropped.
Android: scaleType = "fitCenter"
Scales up or down the source image to the height of the ImageView in the ImageView, and displays the image in the center.
Android: scaleType = "fitEnd"
Scale up or down the source image to the height of the ImageView and display it in the lower part of the ImageView.
Android: scaleType = "fitStart"
Scale up or down the source image to the height of the ImageView and display it in the top part of the ImageView.
Android: scaleType = "fitXY"
Display the source image in the View according to the specified size, stretch the display image, do not maintain the original proportion, fill the ImageView.
Attached below:
The source image is a Pocoyo avatar. The size of the source image is greater than the size of the ImageView, and the size of the source image is smaller than the size of the ImageView.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + CjxpbWcgc3JjPQ = "http://www.2cto.com/uploadfile/Collfiles/20141103/201411030837267.png" alt = "">
Tip: Many people think that fitCenter and centerInside are no different. According to the above analysis, there are actually differences. FitCenter scales up or down the original image to make the height of the source image equal to the height of the ImageView and is displayed in the center. When the original size of the source image is greater than the size of the ImageView, the source image is reduced, the effect is the same as that of fitCenter. When the original size of the source image is smaller than that of ImageView, no size is processed and displayed in the center. The effect is the same as that of center.
The android: adjustViewBounds attribute of ImageView is to determine whether to maintain the aspect ratio of the source image. This attribute does not work independently and must be used with maxWidth or maxHeight.