Android: priority of values

In my application, there are folders of values ​​for different devices in the res folder. For instance:

MDPI Values
HDI Values
Values-v14
Values-v17
Values-W480
Values-w720

and etc.

I wonder what is the priority of these folders for Android?

Imagine a couple of devices:

 first : 480*800 hdpi v14 second: 320*480 mdpi v17 third : 720*1280 hdpi v17 

What folder will Android use for each of them?

+6
source share
2 answers

You can find the priority of resource folders here on this page . It is mainly used to support various devices and configurations.

Android uses certain logic to determine the best suitable resource folder for the device. This is explained in this documentation page .

Regarding your device request:

  • First: 480 * 800 hdpi v14 - values-hdpi
  • Second: 320 * 480 mdpi v17 - values-mdpi
  • Third: 720 * 1280 hdpi v17 - values-w480

In the list you presented, values-w480 (devices with lowest width of 480dp, only from API 13) received the highest rating. Thus, no matter what device meets these criteria, it will receive resources from this folder.

values-vXX (devices with API >= XX) received the lowest value. Therefore, if other folders are not accepted, then only Android receives resources from this folder. See the table listing resource qualifiers for more information on this topic. Resource qualifiers are listed in the table in order of priority of resource qualifiers.

  • First case: normal hdpi - width less than 480dp - So values-hdpi
  • The second case: normal mdpi - width less than 480dp - mdpi values ​​(mdpi values ​​have more weight than v17 values)
  • Third case: an hdpi device with a width of 480dp (720 / 1.5 = 480) API 17 - Values-W480
+8
source

This is what the Android documentation says:

Remember that when the Android system selects which resources to use in runtime, it uses certain logic to determine the β€œbest fit,” Resources. That is, the qualifiers you use do not have to exactly match the current screen configuration in all cases for the system to use them. In particular, when selecting resources based on the size of qualifiers, the system will use resources designed for a screen smaller than the current screen if there are no resources that are better (for example, a large screen will use a screen of normal size resources if necessary). However, if only available resources are available that are larger than the current screen, the system will not use them and your application will fail if no other resources match the configuration device (for example, if all layout resources are marked xlarge, but the device is a normal-sized screen) . For more information on how the system selects resources, read how Android Finds the best resource.

A source

How Android Finds the Best Appropriate Resource

+1
source

Source: https://habr.com/ru/post/949811/


All Articles