What Is The Difference Between -anydpi And -nodpi?

Solution 1:

nodpi

These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.

For instance:

  • drawable-nodpi/dot.png

The dot will appear small on xxhdpi, big on ldpi.

However, the resource resolver will match a specific qualifier if it exists.

For instance

  • drawable-hdpi/eg.png
  • drawable-nodpi-v21/eg.xml

On a Lollipop (API 21) hdpi device, the bitmap is used.

On a Lollipop (API 21) xhdpi device, the vector is used.

anydpi

These resources take precedence in any dpi.

For instance

  • drawable-hdpi/eg.png
  • drawable-anydpi-v21/eg.xml

On a Lollipop (API 21) hdpi device, the vector is used.

On a Lollipop (API 21) xhdpi device, the vector is used.

Reference

Note: anydpi was added in change Ic3288d0236fe0bff20bb1599aba2582c25b0db32.

Solution 2:

I use drawable-nodpi for everything, including plenty of large graphics for my game. An undocumented consequence of scaling up your graphics with -anydpi is that it increases memory use exponentially. So if you have a 1MB graphic in drawable, it will get scaled to 4MB, 16MB, 64MB, or more depending on the resolution of the user device. And device resolutions keep going up. That scaling up doesn't actually increase the sharpness of the graphic, of course. The drawing actions can direct how large each graphic should be in relation to screen size anyway, no need to bloat the app. Nor with multiple resolution specific draw folders.

Solution 3:

The source code contains the following comments (line 639):

/**
 * Value for {@link #densityDpi} for resources that scale to any density (vector drawables).
 * {@hide}
 */
public static final int DENSITY_DPI_ANY = 0xfffe;

/**
 * Value for {@link #densityDpi} for resources that are not meant to be scaled.
 * {@hide}
 */
public static final int DENSITY_DPI_NONE = 0xffff;

Hope this clears out the confusion.

Solution 4:

nodpi: Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.

anydpi: This qualifier matches all screen densities and takes precedence over other qualifiers. This is useful for vector drawables. Added in API Level 21.