Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Values priority

Tags:

android

device

In my app in the res folder, there are values folders for different devices. For example:

values-mdpi
Values-hdpi
values-v14
values-v17
values-w480
values-w720

etc.

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

Let's imagine couple devices:

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

What folder would Android use for each of them?

like image 560
c00p3r.web Avatar asked Jul 19 '13 09:07

c00p3r.web


People also ask

What is android priority?

android:priority. The priority that should be given to the parent component with regard to handling intents of the type described by the filter.

What is the integer that represents the highest priority?

And the highest priority possible would be the maximum integer that android allows, which is (2^31 - 1).

What is res folder in android?

The res/values folder is used to store the values for the resources that are used in many Android projects to include features of color, styles, dimensions etc.


2 Answers

You can find the priority of resource folders here in this page. Basically it is used to support different devices and configurations.

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

Regarding your devices query:

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

In the list provided by you, values-w480 (devices with lowest width of 480dp, only from API 13) has got the highest merit. So whichever device meets that criteria, it'll take resources from that folder.

The values-vXX (devices with API >= XX) has got the lowest merit. So if the other folders are not taken, then only Android takes resources from this folder. Check the table listing the resources qualifiers for more info on that topic. The resource qualifiers are listed in the table in the order of precedence of resource qualifiers.

  • First case: Normal hdpi - less than 480dp width -- So values-hdpi
  • Second case: Normal mdpi - less than 480dp width -- values-mdpi (values-mdpi has got more weightage than values-v17)
  • Third case: hdpi device with width of 480dp (720/1.5 = 480) API 17 -- values-w480
like image 197
Renjith Avatar answered Nov 15 '22 00:11

Renjith


This is what the Android documentation states:

Be aware that, when the Android system picks which resources to use at runtime, it uses certain logic to determing the "best matching" resources. That is, the qualifiers you use don't have to exactly match the current screen configuration in all cases in order for the system to use them. Specifically, when selecting resources based on the size qualifiers, the system will use resources designed for a screen smaller than the current screen if there are no resources that better match (for example, a large-size screen will use normal-size screen resources if necessary). However, if the only available resources are larger than the current screen, the system will not use them and your application will crash if no other resources match the device configuration (for example, if all layout resources are tagged with the xlarge qualifier, but the device is a normal-size screen). For more information about how the system selects resources, read How Android Finds the Best-matching Resource.

Source

How Android Finds the Best-Matching Resource

like image 43
Leon Lucardie Avatar answered Nov 14 '22 22:11

Leon Lucardie