An analysis of the function of ImageView's attribute Android:scaletype _android

Source: Internet
Author: User

Search on the Internet a lot of information, roughly the same, we are copying each other, looking very laborious, not understanding, their own summary, keep the need to see the words to find.
The example in the code is as follows:

Copy Code code as follows:

<imageview
Android:id= "@+id/iv_bit_1"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>
<imageview
Android:id= "@+id/iv_bit_2"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>
<imageview
Android:id= "@+id/iv_bit_3"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>
<imageview
Android:id= "@+id/iv_bit_4"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>
<imageview
Android:id= "@+id/iv_bit_5"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>
<imageview
Android:id= "@+id/iv_bit_6"
Android:layout_width= "@dimen/passcode_width"
android:layout_height= "@dimen/passcode_height"
Android:scaletype= "Fitxy"/>

The query from the API learned that
The structure of the Imageview.scaletype is:

Inheritance relationship
public static final enum Imageview.scaletype extends Enum<e extends enum<e>>
Java.lang.Object
Java.lang.enum<e extends Java.lang.enum<e>>
Android.widget.ImageView.ScaleType

class overview
The option to scale the picture boundary to fit the view boundary.

Constants
public static final Imageview.scaletype CENTER
Centers the image in the view and does not perform scaling. The syntax that can be used in XML:android:scaletype= "center".
Public static Final Imageview.scaletype Center_crop
A balanced scaling image (keeping the original proportions of the image) so that the two coordinates (width, height) of the picture are greater than or equal to the corresponding view coordinates (the negative inner margin). The image is located in the center of the view. The syntax that can be used in XML:Android:scaletype= "Centercrop".
Public static Final Imageview.scaletype center_inside
Balanced zoom image (keep the original proportions of the image) so that the picture's two coordinates (wide, high) are less than equal to the corresponding view coordinates (negative inner margin). The image is located in the center of the view. The syntax that can be used in XML:android:scaletype= "Centerinside".
Public static Final Imageview.scaletype Fit_center
Scale the image using the CENTER method. The syntax that can be used in XML:android:scaletype= "Fitcenter".
Public static Final Imageview.scaletype fit_end
Use the End method to scale the image. The syntax that can be used in XML:android:scaletype= "Fitend".
Public static Final Imageview.scaletype Fit_start
Scales the image using the START method. The syntax that can be used in XML:android:scaletype= "Fitstart".
Public static Final Imageview.scaletype Fit_xy
Use the FILL method to scale the image. The syntax that can be used in XML:Android:scaletype= "Fitxy".
Public static Final Imageview.scaletype MATRIX
When drawing, the image matrix is used to scale. The image matrix can be set by Setimagematrix (matrix). That can be used in XMLsyntax: android:scaletype= "Matrix".
Use code to show the effects of several properties, the effect of screenshots:
Main interface:

Center effect:

Center_crop Effect:

Center_inside Effect:

Fit_center Effect:

Fit_start Effect:

Fit_end Effect:

Fit_xy Effect:

Matrix Effect:

Result analysis:
The original picture I selected was marked as follows: There are butterflies, flowers in the upper left corner, a locust in the lower right corner, and picture pixels greater than 320x 480, various types of differences by looking at the obvious signs of the picture can be glimpse. such as Fit_start, fill the top of the screen, and proportional scaling; instead, Fit_end is placed below the screen, and Fit_center is in the middle. Center_crop cropped the middle part of the picture to fill the screen. Other types can view the analysis themselves.

Related Article

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.