Android drawable 目录可以包含子目录吗? [英] Can the Android drawable directory contain subdirectories?
问题描述
在 Android SDK 文档中,所有与 @drawable/my_image xml 语法一起使用的示例都直接处理存储在我项目的 res/drawable 目录中的图像.
In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my project.
我想知道在 drawable 目录中创建子目录是否明确是不行的.
I am wondering if it is explicitly not okay to create a sub directory within the drawable directory.
例如,如果我有以下目录布局:
For example, if I had the following directory layout:
res/drawable
-- sandwiches
-- tunaOnRye.png
-- hamAndSwiss.png
-- drinks
-- coldOne.png
-- hotTea.png
我可以将金枪鱼沙拉三明治的图片引用为@drawable/sandwiches/tunaOnRye
Could I reference the image of a tuna salad sandwich as @drawable/sandwiches/tunaOnRye
或者我是否必须在 drawable 目录中保持层次结构平坦.
Or do I have to keep the hierarchy flat in the drawable directory.
推荐答案
不,资源机制不支持可绘制目录中的子文件夹,所以是的 - 您需要保持该层次结构平坦.
No, the resources mechanism doesn't support subfolders in the drawable directory, so yes - you need to keep that hierarchy flat.
您显示的目录布局将导致没有可用的图像.
The directory layout you showed would result in none of the images being available.
从我自己的实验来看,在 res/drawable
文件夹内有一个包含任何项目的子文件夹,将导致资源编译器失败——阻止 R.java
文件无法正确生成.
From my own experiments it seems that having a subfolder with any items in it, within the res/drawable
folder, will cause the resource compiler to fail -- preventing the R.java
file from being generated correctly.
这篇关于Android drawable 目录可以包含子目录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!