Android ImageView ScaleType Properties

Source: Internet
Author: User

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

123456789 <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:

MatrixDraw with a matrix (the matrix region starting from the upper-left corner)FitxyZoom in/out of the image to the view size (make sure the picture is fully displayed and full of view)FitstartEnlarges/shrinks the image to the width of the view, displayed in the upper part of the view (the picture will be displayed in full)FitcenterEnlarge/Narrow The picture to the width of the view, centered (the picture will be displayed in full)FitendZoom in/out of the image to the width of the view, displayed in the lower part of the view (the picture will be displayed in full)CenterBy 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 centeredCentercropProportionally enlarge/Shrink the size of the image so that the image is higher than the view, making the picture wider or larger than the view widthCenterinsideThe content of the picture is completely centered, so that the picture is scaled down or the original size (picture than the view hours) so that the picture width is equal to or less than the width of the view (the picture will be full display) attached two experiments: Figure 1: Picture is larger than ImageView 2: Figure ratio ImageView Small experimentMatrix matrices can zoom in and out to show, just post the relevant statement and zoom out the image:
1//Get bitmap high and wide  2 int bmpwidth=bmp.getwidth ();  3 int bmpheight=bmp.getheight ();  4   5//Set reduction ratio  6 double scale=0.8;  7//Calculate the ratio to be reduced by  8 scalewidth= (float) (Scalewidth*scale);  9 scaleheight= (float) (Scaleheight*scale);  11//Generate resize after the Bitmap object of the Matrix Matrix=new Matrix (); Matrix.postscale (ScaleWidth, ScaleHeight); Bitmap re Sizebmp=bitmap.createbitmap (BMP, 0, 0, bmpwidth, Bmpheight, Matrix, True);

1 <imageview 2 android:id= "@+id/image" 3     android:layout_width= "Fill_parent"  4     Android:layout_height = "Fill_parent" 5     android:scaletype= "center" 6     android:src= "@drawable/candle" 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.