Scaled fill screen for Android pictures

Source: Internet
Author: User

when setting properties with Iamgeview Android:scaletype, fill the screen with various problems

/** * Scale the picture proportionally Setadjustviewbounds setmaxwidth setmaxwidth must be set at the same time * * @param context * @param view * Parent Container * @ param image * Picture control * @param source * Picture resource */public static void Setimageviewmathparent (Activity conte XT, LinearLayout view,imageview image, int source) {Bitmap Bitmap = Bitmapfactory.decoderesource (Context.getresources () , source);D isplaymetrics displaymetrics = new Displaymetrics (); Context.getwindowmanager (). Getdefaultdisplay (). Getmetrics (displaymetrics); float Scalew = (float) displaymetrics.widthpixels/(float) bitmap.getwidth (); Image.setscaletype (Scaletype.matrix); Matrix matrix = new Matrix (); Image.setadjustviewbounds (true); if (Displaymetrics.widthpixels < Bitmap.getwidth ()) { Matrix.postscale (Scalew, Scalew);} else {Matrix.postscale (1/scalew, 1/scalew);} Image.setmaxwidth (displaymetrics.widthpixels); float ss = displaymetrics.heightpixels > Bitmap.getheight ()? DisplayMetrics.heightPixels:bitmap.getHeight (); image.setmaxwidth ((int) SS);View.addview (image); if (bitmap! = null && bitmap.isrecycled ()) {bitmap.recycle ();}} 

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.