Android Adaptation (drawable folder) picture adaptation (ii)

Source: Internet
Author: User

Reference from (54090891)

Android Resource file storage:

The Android drawable file can have:

drawable-ldpi (Low Density) drawable-mdpi (medium density) drawable-hdpi (high density) drawable-xhdpi (ultra high Density)

DRAWABLE-XXHDPI (ultra-high-density) drawable-xxxhdpi (ultra-ultra-high-density) drawable-nohdpi (no scaling) of course plus the default drawable

----------The following is the key to understand the content, we must read----------

For example, in a medium-resolution mobile phone, Android will choose the Drawable-mdpi folder under the picture, folder has this image will be used first, in this case, the picture will not be scaled;

However, if the image is not found in the Drawable-mdpi folder, the Android system will first look at the higher level of the drawable-hdpi folder, if you find the image resources to zoom processing, display on the screen;

If there is no drawable-hdpi folder, then go to drawable-xhdpi folder, drawable-xxhdpi folder, drawable-xxxhdpi folder, drawable-nodpi;

If the higher density folder is not found, go to the lower-density folder to find, drawable-ldpi folder search;

If not found, will eventually find in the default drawable folder, if not the default Drawable folder that will be an error. (provided that a picture is made into a number of different resolutions placed in the respective density of the drawable folder)

For example, if the current device DPI is 320, the system will first go to drawable-xhdpi directory lookup, if not found, will find xxhdpi→xxxhdpi→hdpi→mdpi→ldpi in turn. For non-existent drawable-[density] directory skip directly, the middle of any directory to find resources, then stop this lookup.

How to know the dpi of your device:

float xdpi = getresources (). Getdisplaymetrics (). xdpi; float ydpi = getresources (). Getdisplaymetrics (). ydpi;

Knowing the DPI of the device will tell you which drawable folder the device is looking for in the first place: DPI range density corresponding range

Device Density adaptation resource file density
0DPI ~ 120dpi ldpi
120DPI ~ 160dpi mdpi
160DPI ~ 240dpi hdpi
240DPI ~ 320dpi xhdpi
320DPI ~ 480dpi xxhdpi
480DPI ~ 640dpi xxxhdpi

For each density of the icon should be designed to what size in fact, Android also gives the best advice, the recommended size is as shown in the following table:

resource file Density Recommended Size
mipmap-mdpi 48 * 48 (Bo master the measured icon 16 is enough)
mipmap-hdpi 72 * 72 (Bo master the measured icon 32 is enough)
mipmap-xhdpi 96 * 96 (Bo master the measured icon 48 is enough)
mipmap-xxhdpi 144 * 144 (Bo master the measured icon 64 is enough)
mipmap-xxxhdpi 192 * 192 (Bo master the measured icon 72 is enough)

The overall match rule is this:

If the image is in a directory with DPI below the matching directory, the image is considered to be needed for low-density devices and is now displayed on high-density devices, and the image is magnified.

If the image is in a directory with DPI higher than the matching directory, the picture is considered to be needed for a high-density device and is now displayed on low-density devices, and the image is scaled down.

If the picture is in the same directory as drawable-nodpi, the original image size is preserved regardless of the device dpi, not scaled.

Six kinds of general density

Android system in order to simplify the way developers design the user interface for a variety of screens, Android makes a general specification of the actual screen size and range, called "New technology to manage screen size based on available screen widths." Six kinds of general density are

density DPI Range
LDPI (Low) ~120dpi
MDPI (Medium) ~160dpi
HDPI (High) ~240dpi
XHDPI (Ultra High) ~320dpi
XXHDPI (ultra-high) ~480dpi
XXXHDPI (Super super High) ~640dpi

The general density is configured as a baseline in MDPI (Medium), based on the screen configuration of the first-generation Android device (T-mobile G1).

So what is the zoom factor of the six universal densities? With MDPI as the baseline, the magnification (i.e. scaling factor density) under each density directory is as follows

density magnification
ldpi 0.75
mdpi 1.0
hdpi 1.5
xhdpi 2.0
xxhdpi 3.0
xxxhdpi 4.0

For example, if the current device has a DPI of 480 (that is, xxhdpi), the image stored in the MDPI directory will be magnified three times times. For many devices, the DPI is not exactly the six universal density maximum dpi, in this case, how to calculate the magnification of the picture?

If you think about it a little bit, we can get a general-purpose zoom factor (magnification) calculation method: For any device, the image magnification calculation formula for each drawable-[density] directory

Then, the image's implementation display size can be obtained by multiplying the image size by the zoom factor.

Android Adaptation (drawable folder) picture adaptation (ii)

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.