Imageview attributes Android: scaletype

Source: Internet
Author: User

I checked a lot of information on the Internet, which is roughly the same. Everyone copied each other. It was very difficult and hard to understand. I would like to summarize it myself and find it if I needed it.

CodeExample:

 <  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 API query shows that,

The structure of imageview. scaletype is as follows:

Inheritance relationship

Public static final Enum imageview. scaletype extends Enum <E>

Java. Lang. Object

Java. Lang. Enum <E extends java. Lang. Enum <E>

Android. widget. imageview. scaletype

Class Overview

Scales the image boundary to adapt to the option when the view boundary is reached.

Constant

Public static final imageview. scaletypeCenter

Center the image in the view without scaling. Syntax available in XML: Android: scaletype = "center ".

Public static final imageview. scaletypeCenter_crop

Balanced scaling of the image (maintaining the original image proportion), so that the two coordinates (width and height) of the image are greater than or equal to the corresponding View coordinates (negative padding ). The image is located in the center of the view. Syntax that can be used in XML: Android: scaletype = "centercrop ".

Public static final imageview. scaletypeCenter_inside

AverageScale the image (keep the original proportion of the image) so that the two coordinates (width and height) of the image are smaller than or equal to the corresponding View coordinates (negative padding ). 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. scaletypeFit_center

Use the Center Method to scale the image. Syntax available in XML: Android: scaletype = "fitcenter ".

Public static final imageview. scaletypeFit_end

Use the end method to scale the image. The syntax that can be used in XML: Android: scaletype = "fitend ".

Public static final imageview. scaletypeFit_start

Use the start method to scale the image. The syntax that can be used in XML: Android: scaletype = "fitstart ".

Public static final imageview. scaletypeFit_xy

EnableScale the image in fill mode. The syntax that can be used in XML: Android: scaletype = "fitxy ".

Public static final imageview. scaletypeMatrix

The image matrix is used to scale the image. The image matrix can be set through setimagematrix (matrix. The syntax that can be used in XML: Android: scaletype = "matrix ".

You can refer to the following link for more detailed explanations:

Http://blog.sina.com.cn/s/blog_407abb0d0100mao1.html

The code shows the effects of several attributes:

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 image I selected is marked as follows: Butterfly and flowers exist in the upper left corner, a locust is in the lower right corner, and the image pixel is greater than 320 × 480, you can see the differences between different types by looking at the obvious icon of the image. For example, fit_start is filled in the top of the screen and scaled proportionally. On the contrary, fit_end is placed below the screen, while fit_center is in the middle. Center_crop crops the middle part of the image to fill the screen. For other types, you can view the analysis on your own.

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.