Android APP drawable不同文件夹的用法
本文最后更新于:2025年1月4日 晚上
Screen compatibility: https://developer.android.com/guide/practices/screens_support.html
App resources: https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
Support different pixel densities: https://developer.android.com/training/multiscreen/screendensities
Drawable resources : https://developer.android.com/guide/topics/resources/drawable-resource
res/drawable/ is a legacy synonym for res/drawable-mdpi/, indicating that the drawables in that directory are set for mdpi density. If the device is running another density, those images will be downsampled (to ldpi) or upsampled (to anything else) to match the device density.
res/drawable-nodpi/ says “these drawables should not be resampled for any density, but instead should be used as-is on all densities”.
drawable-nodpi will bypass scaling and drawable will use the default scaling:
mdpi = 1x
hdpi = 1.5x
xhdpi = 2x
xxhdpi = 3x
xxxhdpi = 4x
drawable-nodpi is efficient if your code will be doing its own scaling (or no scaling) and you don’t want the image pre-scaled by Android.
There is also drawable-anydpi, just to make things more confusing.
drawable with no specifications will be used if an exact match on density and screen specifications does not exist. drawable-nodpi will be used after drawable.
UPDATE If you have both drawable and drawble-nodpi, the select order is either a more complex rule not documented or Android is broken. Through experimentation I confirmed that devices with screen density < xhdpi will correctly select the drawable image. Devices with screen density >= xhdpi will select the drawable-nodpi.
Selection rule: 1. Pick match to screen density, one of these:
drawable-ldpi
drawable-mdpi
drawable-hdpi
drawable-xhdpi
drawable-xxhdpi
drawable-xxxhdpi
If no match on density, then select one of these
drawable (automatic scaling mdpi=none… xxxhdpi=4x)
drawable-nodpi (no scaling)
drawable-tvdpi
drawable-anydpi (no scaling)
参考
android - Will a density qualified drawable folder or drawable-nodpi take precedence? - Stack Overflow: https://stackoverflow.com/questions/24682094/will-a-density-qualified-drawable-folder-or-drawable-nodpi-take-precedence
android - What is the difference between putting images in drawable and drawable-nodpi folder? - Stack Overflow: https://stackoverflow.com/questions/33631995/what-is-the-difference-between-putting-images-in-drawable-and-drawable-nodpi-fol
玩转Android drawable图片适配 - 漫思 - 博客园: https://www.cnblogs.com/sexintercourse/p/17020569.html
Android 适配(drawable文件夹)图片适配(二) - 张亚楠 - 博客园: https://www.cnblogs.com/huihuizhang/p/9473698.html
android(drawable文件夹)图片适配_drawable是什么文件-CSDN博客: https://blog.csdn.net/xuaho0907/article/details/72848520#:~:text=%E5%A6%82%E6%9E%9C%E5%9B%BE%E7%89%87%E6%89%80%E5%9C%A8%E7%9B%AE%E5%BD%95%E4%B8%BA,%E5%9B%BE%E7%89%87%E5%A4%A7%E5%B0%8F%EF%BC%8C%E4%B8%8D%E8%BF%9B%E8%A1%8C%E7%BC%A9%E6%94%BE%E3%80%82&text=drawable%2Dnodpi%E6%96%87%E4%BB%B6%E5%A4%B9%EF%BC%8C%E8%BF%99%E4%B8%AA,%E5%B0%B1%E4%BC%9A%E5%AE%9E%E9%99%85%E5%B1%95%E7%A4%BA%E5%A4%9A%E5%A4%A7%E3%80%82
Android知识体系之drawable文件夹顺序 - 作业部落 Cmd Markdown 编辑阅读器: https://www.zybuluo.com/TryLoveCatch/note/590965
Android drawable文件夹那些事_安卓drawable文件夹的作用-CSDN博客: https://blog.csdn.net/qq_34341338/article/details/86706751