1

I'm wondering how Android fetches and renders drawables if there isn't an accurately-scaled drawable in a relevant folder?

For example, let's say that I'm trying to render a drawable on a device that is hdpi, large, and running Android 2.3. The drawable that the app is looking for is available in xhdpi, mdpi, xlarge, and large, but not hdpi or large (for whatever reason).

Specifically, I'm wondering how Android decides which drawable to fetch? I would assume that it would take preference to a larger drawable (xhdpi or xlarge) but does it give preference to DPI or screen size? And also, does it apply scaling to the drawable as listed in http://developer.android.com/design/style/iconography.html (i.e. an xhdpi drawable would render as 1.5/2 of it's actual dimensions)? If so, does it load the original drawable or the scaled drawable in memory?

Also, since screen size (large, xlarge) are deprecated in Android 3.2+, how would you name drawable folders for an app that runs 2.2+? Would drawable-large-sw600dp work on all devices, or copy the drawables into drawable-large and drawable-sw600dp?

I know similar questions have been asked, but they are less complex and less specific, so any insight would be great!

Phazor
  • 1,032
  • 1
  • 9
  • 15

1 Answers1

2

You do not need to provide alternative resources for every combination of screen size and density. The system provides robust compatibility features that can handle most of the work of rendering your application on any device screen, provided that you've implemented your UI using techniques that allow it to gracefully resize (as described in the Best Practices, below). and check this Density independence

At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:

  1. The system uses the appropriate alternative resource Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with the hdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.

  2. If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate. However, 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. For more information about how Android selects alternative resources by matching configuration qualifiers to the device configuration, read How Android Finds the Best-matching Resource.

enter image description here

Shyam
  • 6,376
  • 1
  • 24
  • 38
  • 1
    Thank you, but I'm fully aware of that. What I'm asking for is what happens when the app is run on a device that you haven't provided ideal assets for. – Phazor Dec 28 '13 at 05:14
  • Thanks for the thorough response. I take it that means __DPI takes precedence over a size reference? – Phazor Dec 29 '13 at 21:45