Android work and study notes Image Adaptive imageview attributes Android: scaletype

Source: Internet
Author: User

Android adaptation has always been a headache.
Especially for images. Sometimes they are always large and small.
After downloading images from the server, write a tool class to reduce it to a specified size, and then put it in the specified control.

In fact, this is not so troublesome. The imageview control has an Android: scaletype attribute.
That is, imageview. setscaletype (imageview. scaletype)
The function of the SDK is as follows: options for scaling the bounds of an image to the bounds of this view.
In general, it indicates the option of scaling boundary to control the boundary range of the Image view.

To put it bluntly, it is to control the display mode of imageview boundaries.

 centercenter the image in the view, but perform no scaling. the image is displayed in the center according to the original size. When the length/width of the image exceeds the length/width of the view, the center part of the screenshot is displayed. center_cropscale the image uniformly (maintain the image's Aspect Ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding ). scale up the image size in the center so that the image length (width) is equal to or greater than the view length (width) center_insidescale the image uniformly (maintain the image's Aspect Ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding ). the image content is displayed in the center, and the image length/width is equal to or less than the view length/width fit_centerscale the Image Using center by scale down or the original size. increase or decrease the image width proportionally to the width of the view, and display the fit_endscale the image using end in the center. scale up or down an image to the width of the view, and display the image using start at fit_startscale in the lower part of the view. scale up or down an image to the width of the view in proportion, and display the image using fill in the top part of the view. increase or decrease the image size proportionally to the View Size and display matrixscale using the image matrix when drawing. draw with matrix 

For example:

If the length-width ratio of the obtained image is fixed, assume.

The design must display the size of 60*60 at a resolution of 480*800.

Set the attributes:

 
Android: layout_width = "40dip" Android: layout_height = "40dip" Android: scaletype = "fitxy"

In this way, as long as the ratio of the obtained image is, no matter how large the image is, it will be displayed in 60*60 size.

(60px is 40dip under 480*800, (60-0.5)/1.5 = ...)

In this way, you do not need to write a single tool to scale the image. In addition, the adaptability is greatly enhanced when multiple resolutions are adapted.

 

 

Address: http://www.cnblogs.com/chorrysky/archive/2012/05/11/2496107.html

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.