Android Imageview.scaletype have a picture of the truth

Source: Internet
Author: User

Originally did not intend to write this article about ScaleType, after all, online a lot, but considering the next Photoview source of the analysis will use this knowledge, and do not want to let the reader to find other related articles, and some of the article is wrong to explain, So here's a look at the different types of imageview.scaletype, what is the difference, which one should we use in practice?

  • How to use

    • In XML: android:scaletype= "type"
    • In Java code: Imageview.setscaletype (Type)

      Note that this property only works with ImageView.

  • type action
    • Matrix: Draw with a matrix, starting from the origin of the original image, as far as possible to fill the size of the ImageView control, It's not full. Setting the scale on the matrix displays an area without an image on the ImageView
    • fitxy: Brute force stretching or scaling, that is, regardless of the imbalance of the picture, stretching or scaling independently of each direction to the size of the ImageView, This scenario is likely to be disproportionately large, imageview are full of images, which is the only type of these types that do not scale the size of the picture, so generally do not use
    • fitstart: Proportional stretching or scaling, you can consider the gradual process of transformation, The image is scaled up or down proportionally until the entire image is in the ImageView display area, and then the adjusted image is placed from the upper-left corner of the ImageView, that is, the top edge of the image and the top edge of the ImageView (except padding)
    • Fitcenter: With Fitstart, just put the adjusted image in the middle of the ImageView
    • fitend: With Fitstart, put the adjusted image in the place of ImageView, Aligns the bottom edge of the image with the bottom edge of the ImageView (and, of course, the padding)
    • Center: Keep the original image size, do not stretch and scale the image, directly put the image in the middle of the ImageView, the image is large, the middle part of the image is captured
    • Centercrop: Proportional stretching and scaling to ensure that the width and height of the image are <=imageview and high, and then put the adjusted image in the middle of ImageView, in which case ImageView may have not been covered by the image of the part
    • centerinside: Proportional stretching and scaling to ensure that the width and height of the image are >=imageview and high, and then put the adjusted image in the middle of ImageView, when the entire imageview is covered with the image of the
  • Type Summary
    ScaleType altogether there are 8 types, how to remember these types of characteristics, here we apply the idea of classification, from these several ways to choose to have in common place in a class, so I put them into three categories:
    • Fit Fit Class: fit* This category, which is characterized by a guarantee that there will be no image drawing outside the ImageView display, that is, the image is displayed all within the ImageView, regardless of whether or not he has a proportional change, where to place the ImageView
    • Center Center class: center* This kind of type, this kind of feature is to ensure that the image is in the middle of ImageView, of course, can also be the whole ImageView
    • Matrix: This is more special, and most commonly used, so the next blog is devoted to the matrix
  • the

    The original picture is larger than the size of the ImageView.


    The original picture is smaller than the size of the ImageView.

Forgive me for being too lazy ~ ~ ~ from http://blog.csdn.net/xilibi2003/article/details/6628668

After reading these are not scaletype have a clear understanding of it, I hope you can in the future projects to choose the right type of their own, of course, many cases directly with. 9.png more Convenient

Android Imageview.scaletype have a picture of the truth

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.