How does Android find appropriate resource files based on the delimiter?

Source: Internet
Author: User

How does Android find appropriate resource files based on the delimiter?

Reprinted please indicate the source: http://blog.csdn.net/zhaokaiqiang1992

This article mainly introduces how the Android system filters and selects resource folders based on certain rules when we use a qualifier to modify resource folders, such as drawable-en-ldpi.

This article is not a serious translation. If you want to view the original article, stamp Providing Resources.

As we all know, when we use a qualifier to modify the resource folder, such as drawable or values, the Android system will be based on the properties and configurations of the device where the runtime is located, dynamic selection of the most appropriate resource file, then, how is this process carried out? The following uses the drawable folder as an example to describe the selection process and precautions.

Now let's assume that the following folders contain different versions of the same image:

Drawable/drawable-en/drawable-fr-rCA/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/

Assume that the device configuration is as follows:

Locale = en-GB Screen orientation = port Screen pixel density = hdpi Touchscreen type = notouch Primary text input method = 12key

By comparing the device configurations and the drawable folders modified by these available delimiters, the Android device finally selects the images from the drawable-en-port folder.

The system determines why the image in the folder should be selected based on the following logic:

Translated version:

Created with Rapha? L 2.1.2 1. Exclude the delimiters that conflict with device configurations 2. Select the next qualifier based on the priority of the qualifier table 3. Is there any resource folder that uses this qualifier? 4. Exclude folders that do not contain this qualifier (there should be a loop to Step 3 that cannot be drawn) Yes No

First, remove the drawable folder that conflicts with the device configuration. Because the drawable-fr-rCA/folder conflicts with the language environment en-GB, it is directly excluded. The following figure shows the resource folders:

Drawable/drawable-en/ Drawable-fr-rCA/Drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/

Note:The pixel density modifier of the screen will not be excluded because it is different from the device configuration, even if our device is hdpi, however, drawable-port-ldpi/will not be excluded because of the qualifier, because at this stage, all screen density will be considered for adaptation. For more information, see Support Multiple Screen.
2. Select the next Modifier with a higher priority according to the order in the table. (From MCC, keep going)

The order of the delimiters is as follows. The priority decreases from top to bottom. Because many of them are rarely used, this is part of it. For more details, refer to the original article.

Configuration Example of a qualifier Value
MCC MNC Mcc310
Language En-rUS
Layout direction Ldrtl ldltr
Minimum Width qualifier Sw320dp
Width obtained W720dp
Gain height 201720dp
Screen Size Large
Screen Long notlong
Screen direction Port land
UI Mode Car appliance watch
Night mode Night notnight
Screen pixel density Mdpi nodpi
Touch screen type Notouch finger

3. Are there any folders containing these delimiters?
-If it is NO, return the second step and check the next qualifier. (In this example, NO is answered before the language qualifier is found)
-If YES, continue step 4.
4. Exclude the resource folders that do not contain this qualifier. In this example, the system will exclude all resource folders that do not contain language delimiters.

Drawable/Drawable-en/drawable-en-port/drawable-en-notouch-12key/ Drawable-port-ldpi/ Drawable-port-notouch-12key/

Warning:If the qualifier is screen density, the system selects the resource folder closest to the screen density of the device. Generally, Android is more inclined to narrow down a relatively large image than to enlarge a relatively small image.
5. Return and repeat steps 2, 3, and 4 until there is only one folder left. In this example, the screen direction is the next qualifier. Therefore, folders that do not specify the screen direction qualifier are excluded.

Drawable-en/Drawable-en-port/ Drawable-en-notouch-12key/

Now we have left the folder drawable-en-port.

Although this step is executed when we request each resource file, the system has optimized some aspects. Once our device configurations are known, folders that never match will be excluded. For example, if our language is configured in English, the resource folders with other language delimiters will be excluded from the system and will not be checked. This will improve our performance. Of course, the resource folder without a specified language qualifier still exists.

When we select a screen size-based limitation, if there is no suitable resource folder, the system will select a resource folder smaller than the current screen. For example, if we do not configure a proper resource file for the large screen, the system selects a normal screen size resource. However, if the screen size modifier of the currently available resource folder is larger than the current screen, our system will not use these resources, but will crash directly. For example, if our layout resources only have the xlarge qualifier, And if we run on the normal-size device, it will crash.

Note:The priority order of the preceding delimiters is more important than the number of delimiters. For example, before the fourth part, the optional resource folder contains three delimiters that match the current device, while the drawable-en has only one qualifier, but because the priority of the language qualifier is relatively high, so the drawable-port-notouch-12key folder is ruled out directly.

Related Article

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.