关于理解 Android 资源文件夹
Regarding understanding Android resource folder
我进行了研究,并深入研究了 Android 资源文件。根据 this link,它说 Android 将用户的资源从代码中外部化和分离,以允许使用
这些资源的 IDs 将在 R.class 中生成,这里是文本:
Once you externalize your application resources, you can access them using resource IDs that are generated in your project's R class.
(1):存在'res'文件夹是否意味着生成R.javaclass?换句话说,R.java 是否代表 "ids" 分配给 'res' 文件夹内的任何值?
(2): 是否可以将我的 'layout' 或 'string' 文件放在除 'res' 之外的任何其他文件夹中?
R.java file is an auto-generated file by aapt (Android Asset Packaging
Tool) that contains resource IDs for all the resources of res/
directory. when you create any component in the xml file, id for the
corresponding component is automatically created in this file.
当使用 android studio 创建布局文件时,它会自动将其放在 layout
文件夹下,但是当您手动创建它时,它将被归类为父文件夹,例如:创建布局文件under drawable 将被称为 R.drawable.mLayout
,android studio 会将其显示为警告,但它会正常工作,所以是的,你可以将任何类型的 xml 放在任何文件夹下,它会正常工作, 更容易将其归类为默认值以获得更高的可读性和更清晰的架构
Is R.java a representation to "ids" assigned to any values inside
'res' folder?
很有可能是R.java
的想法。
Is it possible to place my 'layout' or 'string' files in any other
folders aside from 'res'?
是的,你可以这样做,但在你开始之前,确保你检查了 project 结构视图,而不是 android[= 等其他选项35=]结构视图。
在你的build.gradle
android {
....
sourceSets {
main {
res.srcDirs = [
"src/main/module-res/compose"
];
}
}
}
然后创建与您声明的类似的所需目录。
这是一个示例图像,显示它可以工作。
它的好处是你可以创建更多的res
文件夹(只需将它添加到数组中并用逗号分隔)。请注意,每个 res 文件夹必须有自己的 drawable、layout 等 文件夹。
示例:
res.srcDirs = [
"src/main/module-res/compose",
"src/main/module-res/design",
"src/main/module-res/extra"
];
我进行了研究,并深入研究了 Android 资源文件。根据 this link,它说 Android 将用户的资源从代码中外部化和分离,以允许使用 这些资源的 IDs 将在 R.class 中生成,这里是文本:
Once you externalize your application resources, you can access them using resource IDs that are generated in your project's R class.
(1):存在'res'文件夹是否意味着生成R.javaclass?换句话说,R.java 是否代表 "ids" 分配给 'res' 文件夹内的任何值?
(2): 是否可以将我的 'layout' 或 'string' 文件放在除 'res' 之外的任何其他文件夹中?
R.java file is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory. when you create any component in the xml file, id for the corresponding component is automatically created in this file.
当使用 android studio 创建布局文件时,它会自动将其放在 layout
文件夹下,但是当您手动创建它时,它将被归类为父文件夹,例如:创建布局文件under drawable 将被称为 R.drawable.mLayout
,android studio 会将其显示为警告,但它会正常工作,所以是的,你可以将任何类型的 xml 放在任何文件夹下,它会正常工作, 更容易将其归类为默认值以获得更高的可读性和更清晰的架构
Is R.java a representation to "ids" assigned to any values inside 'res' folder?
很有可能是R.java
的想法。
Is it possible to place my 'layout' or 'string' files in any other folders aside from 'res'?
是的,你可以这样做,但在你开始之前,确保你检查了 project 结构视图,而不是 android[= 等其他选项35=]结构视图。
在你的build.gradle
android {
....
sourceSets {
main {
res.srcDirs = [
"src/main/module-res/compose"
];
}
}
}
然后创建与您声明的类似的所需目录。 这是一个示例图像,显示它可以工作。
它的好处是你可以创建更多的res
文件夹(只需将它添加到数组中并用逗号分隔)。请注意,每个 res 文件夹必须有自己的 drawable、layout 等 文件夹。
示例:
res.srcDirs = [
"src/main/module-res/compose",
"src/main/module-res/design",
"src/main/module-res/extra"
];