android: 如何在 `mipmap` 文件夹中创建可以在代码和布局中访问的子文件夹

android: How can I create subfolder in a `mipmap` folder, that can be accessed in code and layouts

我的图像资源在各个 mipmap 文件夹(mipmap-xhdpimipmap-xxhdpi 等)中它们都在每个目录中的一个级别中。

我想创建一个子文件夹,例如 "sprites",我可以在代码中引用

R.mipmap.sprites.sprite_name

如何在我的 mipmap 文件夹中创建可用的子文件夹?

当我在 mipmap 文件夹中创建一个新目录时(使用 New -> Directory),该目录及其内容对我指定资源的任何地方都是不可见的,即:

• 在我的 xml 布局的设计视图中,当我浏览背景或图像按钮的图像资源时,子文件夹被隐藏。

• 在代码中,当我指定图像资源时(R....子文件夹被忽略)。

有正确的方法吗?似乎还有一些其他目录选项,在 New -> Folder 类别下,我有:

Assets folder,描述为 "create a source root for assets to be included in the apk," 但我不想要根目录,我想要子目录。

Res Folder, "source root for android resource files" 1.我看不出这与资产有何不同,2.同样,我不想要根。

还列出了其他几种我不熟悉的文件夹类型。

如果这做不到,那么在一个项目中包含(和组织)数百(或数千)个图像资源的正确方法是什么?将它们全部放在一个目录中真的是唯一的方法吗?

How can I create usable sub-folders in my mipmap folders?

你不能。任何时间的资源目录,mipmap或其他,不能有子目录。

what is the correct way to include (and organize) hundreds (or thousands) of image resources in a project? Is the only way to do it really to have them all in a single directory?

如果您要使用资源,那么是的,尽管我会将它们放在 drawable 目录中。 mipmap 主要用于启动器图标。

the mipmaps are special because the app will display images of a different resolution depending on the device resolution

没有。 mipmapdrawable 资源支持在运行时进行资源重采样,但它基于密度而非分辨率。

正如 ByteHamster 指出的那样,您可以在 assets/ 中放置任何类型的目录结构,但您需要将适当的值放入 BitmapFactory.Options 以帮助基于密度的重采样。

是的,您必须将所有资源保存在一个文件夹中,因为您可能知道,不同的文件夹用于 target different device classes

按前缀组织资源的正确方法:如 official Android documentation 所述,您应该使用前缀使资源以有意义的顺序出现。