Android ImageView ScaleType Properties

Source: Internet
Author: User

The ScaleType property is often used when using ImageView , such as:

<imageview android:layout_width= "50DP"  android:layout_height= "50DP"  android:scaletype= "Matrix"  android:src= "@drawable/sample_small"/> 

  

The individual values of the ScaleType property always do not remember the difference. Find some time to sum up today:

ScaleType attribute values are: Matrix fitxy fitstart fitcenter fitend Center Centercrop centerinside

The differences between them are as follows:

Matrix is drawn with matrices (The matrix region starting from the upper-left corner)  fitxy The image is not scaled up/down to the view size display (make sure the picture is fully displayed and full of view)  Fitstart enlarges/ shrinks the image to the width of the view, which is displayed in the upper part of the view (the picture is displayed in full )  fitcenter enlarge/ shrink the picture to the width of the view, centered (the picture will be displayed in full )  fitend enlarge/ shrink the image to the width of the view, displayed in the lower part of the view (the picture will be displayed in full )Center by the original size of the picture is displayed , when the picture is wider than the width of the view, then the center portion of the image is captured, when the picture is less than the width of the view, the picture is centered centercrop proportionally enlarges/shrinks the size of the image so that the image is higher than the view, making the picture wider or larger than the view width centerinside The contents of the picture to the full center display , so that the picture is scaled down or the original size (picture than view hours) so that the picture width is equal to or less than the width of the view (The picture will be displayed in full) two experiments are attached:Figure 1: The picture is larger than the ImageViewFig. 2: Small experiment of graph ratio ImageViewMatrix matrices can zoom in and out to show, just post the relevant statement and zoom out the image:
1 //get the high and wide bitmap2 intBmpwidth=bmp.getwidth ();3 intbmpheight=bmp.getheight ();4  5 //Set scale down6 Doublescale=0.8; 7 //figure out the scale to be narrowed down.8Scalewidth= (float) (scalewidth*Scale ); 9Scaleheight= (float) (scaleheight*Scale ); Ten   One //Bitmap object after generating resize AMatrix matrix=NewMatrix (); - Matrix.postscale (ScaleWidth, scaleheight); -Bitmap resizebmp=bitmap.createbitmap (BMP, 0, 0, bmpwidth, bmpheight, Matrix,true);

1 <23     android:layout_width= "fill_parent"  4     5      6     7 />

* * To note that the Drawable folder inside the image name can not be capitalized

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.