ImageView Properties Android:scaletype Set the best scale picture display

Source: Internet
Author: User

To achieve the picture carousel, the previous large picture proportions will be automatically scaled in Guidegallery, and later edited to change the size of the image. The screen does not fit on the large screen. Tried a lot of ways to finally solve. First say the properties of the ImageView. It can be implemented in Java code, or it can be set in an XML file.

Imageview.setscaletype (ImageView.ScaleType.FIT_XY);

Here we focus on understanding ImageView's attribute Android:scaletype, namely Imageview.setscaletype (Imageview.scaletype). Android:scaletype is a size that controls how the picture resized/moved to the ImageView. Imageview.scaletype/android:scaletype value difference: Center/center  by the original size of the image is displayed, when the picture is longer/wider than the length/width of the view, then the center portion of the image is displayed Center_crop/centercrop  proportionally enlarges the size of the image so that the image is long (wide) equal to or greater than the length (width) of the view center_inside/centerinside the  contents of the picture are displayed in a complete center. The image is scaled up/down to the width of the view by scaling it down or the original size to make the picture long/wide equal to or less than the length/width of the view fit_center/fitcenter the  picture, centered on the display fit_end/fitend   Enlarges/shrinks the image to the width of the view, displayed in the lower part of the view Fit_start/fitstart the  picture proportionally to the width of the view, displayed in the upper part of the View Fit_xy/fitxy  The picture is not scaled up/down to the view size display Matrix/matrix is drawn with a matrix

at first I did not understand matrix matrices, the web search found that the original matrix can be scaled to zoom the image to display, here do not expand in-depth understanding, just post related statements, reduce the image:

Get the high and wide bitmap
int Bmpwidth=bmp.getwidth ();
int Bmpheight=bmp.getheight ();

Set scale down
Double scale=0.8;
Figure out the scale to be narrowed down.
Scalewidth= (float) (Scalewidth*scale);
scaleheight= (float) (Scaleheight*scale);

Bitmap object after generating resize
Matrix matrix=new Matrix ();
Matrix.postscale (ScaleWidth, ScaleHeight);
Bitmap resizebmp=bitmap.createbitmap (BMP, 0, 0, bmpwidth, Bmpheight, Matrix, True);


Implemented in Java code

Holder.img.setScaleType (Scaletype.center_inside);

     xml implementation, the key is android:layout_width=" Fill_parent ",  android:layout_height=" 120DP "These two properties, if not fill_parents will appear in the large screen can not be filled, the right half of the left is not content. Height also do not set warp_content, set a suitable proportion of height, warp_content is prone to the effect of severe proportions of deformation.   

<imageview
Android:id= "@+id/gallery_image"
Android:layout_width= "Fill_parent"
android:layout_height= "120DP"
android:scaletype= "Fitxy"
/>


ImageView Properties Android:scaletype Set the best scale picture display

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.