Influence of drawable density on code

Source: Internet
Author: User

ConfigureProgram:

 
<Supports-screens Android: resizeable = "true" Android: smallscreens = "true" Android: normalscreens = "true" Android: largescreens = "true" Android: xlargescreens = "true" Android: anydensity = "true"/>

 

ThenCodeCall bitmapfactory. decoderesource (read a resource,

If the mobile phone is mdpi, the read size is the same as the image size.

If the mobile phone is xhdpi, but the drawable-xhdpi does not include this file, the Read File is twice the original image, it seems that android doubles the files in drawable and copies them to the drawable folder.

If no image is displayed in each directory, Android automatically obtains the following file size ratio:

Ldpi 120

Normal 240

Hdpi 1, 360

Xhdpi 480

To read the same size at all density, do you have to copy all the images to the corresponding density path?

Otherwise, the Code cannot predict the size of the image to be read? Actually, yes.

 

Bitmapfactory. Options opt = new bitmapfactory. Options (); opt. intargetdensity = nmyscaletimes = 1? Displaymetrics. density_medium: displaymetrics. density_xhigh; bitmap BMP = bitmapfactory. decoderesource (m_res, (integer) resurl. geturl (nreskey), OPT );

In the above Code, when nmyscaletimes = 1, the image is not scaled; otherwise, the size of xdpi is exactly twice that of medium, and medium is not scaled.
In this way, you only need to put the original image in drawable-mdpi. It doesn't matter if drawable-xhdpi is not put. If it is put, it will be placed twice as large as the original size graph.

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.