What Is The Difference Between -anydpi And -nodpi?

匆匆过客 提交于 2019-11-26 18:52:14

问题


If you use the Vector Asset wizard in Android Studio 1.5.0, any vector drawable XML you import using that wizard goes into res/drawable/.

However, the build/ directory, and the resulting APK show that those XML files get moved into a res/drawable-anydpi-v21/ resource directory. The -v21 part makes sense, as VectorDrawable is only supported on API Level 21+. However, -anydpi seems to be undocumented. I would have expected -nodpi, both for the original import destination and for where the build system elects to move it.

Has anyone seen official statements for what -anydpi means, and what its relationship is with -nodpi? I am looking for practical effects, not merely what some code comments hint at.


回答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.




回答2:


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.




回答3:


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.




回答4:


I use drawable-nodpi for everything, and I have a lot of big graphics. One undocumented consequence of 'scaling up' your graphics is that it increases memory use exponentially. So if you have a 100M graphic in 'drawable' it will get scaled to 400M or 1.6G depending how high the resolution of the user device is. And device resolutions keep going up. That scaling up doesn't actually increase the 'sharpness' of the graphics, of course. The drawing actions can direct how big the graphics should be in relation to screen size anyway, no need to bloat the app with multiple draw folders.



来源:https://stackoverflow.com/questions/34156957/what-is-the-difference-between-anydpi-and-nodpi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!