ScaleType attribute of ImageView

Source: Internet
Author: User

ScaleType attribute of ImageView

ImageView is often used:

ImageView attributes android: scaleType, that is, ImageView. setScaleType (ImageView. ScaleType. fitCenter)

Android: layout_width = "60dp"
Android: layout_height = "60dp"
Android: scaleType = "FitCenter"
Android: src = "@ Drawable/a1"/>

ScaleType has eight attributes: fitCenter, fitStart, fitEnd, fitXY, center, centerCrop, centerInside, and matrix.

Their differences are:

FitCenter: The default status of the ImageView. The image is displayed in the ImageView by scale up/down center.
FitStart: Scale Up or down an image to the width of the View, and display the image on the top of the View.
FitEnd: Scale Up or down an image to the width of the View, and display the image in the lower part of the View.
FitXY: Scale Up or down an image to the View Size, display it completely, and fill the View
Center: The image is centered according to the original size. When the image length/width exceeds the View length/width, the center part of the screenshot is displayed.
CenterCrop: Scale up or down the image size in the center, so that the image height is equal to the View height, so that the image width is equal to or greater than the View width
CenterInside: Display the entire image content in the center. scale down the image size greater than ImageView. The image smaller than ImageView remains unchanged and is displayed in the center.
Matrix: Scale the Image Based on A 3x3 matrix (from the upper left corner of the matrix)

There is a picture with the truth:


Figure 1: The Source image is larger than the ImageView. Figure 2: The Source image is smaller than the ImageView image.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + kernel + cda-vcd4kpha + kernel/J0tS2r8ysy/kernel + o6zV4sDvsrvVub + kernel/bP4LnY0 ++ 5 KOsy/kernel = "brush: java; "> // obtain the height and width of Bitmap. int bmp = bmp. getWidth (); int bmpHeight = bmp. getHeight (); // set the scale-down ratio to double scale = 0.8; // calculate the scale-down ratio scaleWidth = (float) (scaleWidth * scale); scaleHeight = (float) (scaleHeight * scale); // The Bitmap object after resize is generated. Matrix matrix = new Matrix (); matrix. postScale (scaleWidth, scaleHeight); Bitmap resizeBmp = Bitmap. createBitmap (bmp, 0, 0, bmp width, bmpHeight, matrix, true );For details about how to use the ImageView control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.