Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android default density values when the current is missing

I had a question about densities and how Android chooses the right values folder for the current density. I think I've found the answer but I am not completely sure so I'll post what I've found. At least, this post may help someone.

For example, if I only include folders values, values-hdpi and values-xxhdpi, what does Android do when the current density is xhpdi?

It seems that Android looks for a higher density folder, so it will use values-xxhdpi.

And what happens when the current density is xxxhdpi?

It seems that, if Android can't find a higher density folder, it looks for a lower one, so it will use values-xxdpi too.

Android will never use the default values folder for a value that is defined in some specific values-*dpi folder.

To sum up, supposing I only have values, values-xxhdpi and values-hdpi:

  • Values in values-hdpi will be used for devices with densities ldpi, mdpi and hdpi.
  • Values in values-xxhdpi will be used for devices with densities xhdpi, xxhdpiand xxxhdpi.
  • Values in values won't be ever used if they are defined in any values-*dpi folder.

Let me know what you think about this.

Thanks

like image 489
Ferran Maylinch Avatar asked Jun 16 '14 14:06

Ferran Maylinch


1 Answers

density qualifier is an exception of how resource matching works.

Screen pixel density is the one qualifier that is not eliminated due to a contradiction. Even though the screen density of the device is hdpi, drawable-port-ldpi/ is not eliminated because every screen density is considered to be a match at this point.

Providing Resources

when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.

Supporting Multiple Screens

So in case of density Android may use the default folder, but may also decide to use one that is not an exact match. Of course the substantiation is about drawable resources, but the mechanism probably works the same also for all other resources. Otherwise there could be a problem with drawables not matching other resources because they were chosen using different rules.

like image 198
mike_m Avatar answered Nov 09 '22 10:11

mike_m