"Internship Program Record" (iii) Adjust network image fixed width and height

Source: Internet
Author: User

Many times the size of the server-side image is not uniform. Setting this property in ImageView allows the image to be displayed in a uniform size.

Android:scaletype= "Centercrop" Android:scaletype is a size that controls how the picture resized/moved to the ImageView. The meaning difference of Android:scaletype value: Center/center is centered on the original size of the image, and when the picture is longer/wider than the length/width of the view, the center portion of the image is displayed Center_crop/centercropProportionally 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/centerinsideCenter the contents of the picture in full, 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/fitcenterEnlarges/shrinks the image to the width of the view, centered on the display Fit_end/fitendEnlarges/shrinks the image to the width of the view, displayed in the lower part of the view Fit_start/fitstartEnlarges/shrinks the image to the width of the view, displayed in the upper part of the view Fit_xy/fitxyPut the picturedo not proportionallyEnlarge/Shrink to view size display Matrix/matrixUse a matrix to draw

The percentage of images you get from the network may not be what you want, so you need to set the width in your code

//Download ImageBitmap Bitmap =posterbmpprovider.getinstance (). LoadImage (URL); Linearlayout.layoutparams Linearparams=(Linearlayout.layoutparams) viewholder.img. Getlayoutparams ();//take control view current layout parameters                intwidth =bitmap.getwidth (); intHeight =bitmap.getheight (); //defines the width and height of a pre-converted picture                intNewwidth = Systemutils.getscreenwidth (mcontext) *4/6; intNewheight = Systemutils.getscreenwidth (mcontext) * 3/7; floatScaleWidth = ((float) newwidth)/width; floatScaleHeight = ((float) newheight)/height; //Create a Matrix object for manipulating picturesMatrix Matrix =NewMatrix (); //Zoom Picture ActionMatrix.postscale (ScaleWidth, ScaleHeight); //Create a new pictureBitmap Resizedbitmap = Bitmap.createbitmap (Bitmap, 0, 0, width, height, matrix,true); ViewHolder.img.setImageBitmap (RESIZEDBITMAP);

"Internship Program Record" (iii) Adjust network image fixed width and height

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.