Android Learning Note: How to set the way images are displayed in ImageView

Source: Internet
Author: User

When we use ImageView to display pictures, the size of the film is not exactly the same as the size of the ImageView. This involves how to set the display image.

An important attribute of ImageView is ScaleType, which is used to represent the way a picture is displayed, and there are a number of values. Alternatively, you can set the Android:scaletype property of the ImageView in the XML file to achieve the adjustment effect.

Here we describe the meanings of the various settings:

1. Scaletype.center (android:scaletype= "CENTER" in the corresponding XML file)

The picture is displayed in the middle of the view, but not scaled, and if the picture is larger than the ImageView control, the middle part of the picture is captured, or the picture is centered directly if it is less than.

2. Scaletype.fit_center (android:scaletype= "Fitcenter" in the corresponding XML file)
The default state of the ImageView, large graphs, and so on, so that the whole picture can be centered in the ImageView, small graphs and other proportional amplification, the same overall center display in the ImageView.

3. Scaletype.center_crop (android:scaletype= "Centercrop" in the corresponding XML file)
Keep the short edge of the image consistent with the length of the edge of the ImageView (which may be zoomed in or out), and then zoom in or out on the other side of the image in proportion to the short-sided magnification or reduction.
Note: This is not as fit_center as scaling. Causes the image to zoom in and out of the original inconsistent length and width ratio.
The middle part of the picture is displayed after the last intercept.
This is useful in some scenarios, such as the need for images to fill the entire imageview, but it can be tolerated to distort or intercept some of the images after zooming.

4. Scaletype.fit_xy (android:scaletype= "Fitxy" in the corresponding XML file)

Scale the picture proportionally to the same size as the ImageView. Compared to Center_crop, this ensures that the picture fills the entire imageview. It also ensures that the long and wide scales do not affect each other.

Although it may also cause scaling inconsistencies, it will not eventually cause the image to be cut.


5. Scaletype.center_inside (android:scaletype= "Centerinside" in the corresponding XML file)
The picture size is larger than ImageView, until the entire picture can be centered in the ImageView, the picture is less than ImageView, and is centered directly, not enlarged.
For images larger than ImageView, the effect is equal to fit_center, and the ratio is reduced.

6, there are several other situations, not very common, here simply say

Scaletype.fit_end: Zoom in the same way as Fit_center, just display the picture on the right or bottom instead of the center.

Scaletype.fit_start: Zoom in the same way as Fit_center, just display the picture on the left or top rather than centered.

Scaletype.matrix: The image is scaled according to a 3x3 matrix

Android Learning Note: How to set the way images are displayed in ImageView

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.