简体   繁体   English

为什么我们用@dimen而不是@dimens引用android中的dimens.xml文件?

[英]why we refer the dimens.xml file in android with @dimen not @dimens?

I have made a new value resource file in the android studio project as name dimens but while referring to it from XML I have to use the attribute @dimen我在 android 工作室项目中创建了一个新的值资源文件作为名称dimens但在从 XML 引用它时我必须使用属性 @dimen

I am really curious to know the referring tag must have to be the same as the file name but it is not.我真的很想知道引用标签必须与文件名相同,但事实并非如此。

I have seen the same pattern in strings and colors.我在字符串和 colors 中看到了相同的模式。

But it is like that?但它是那样的吗? any clue?任何线索?

在此处输入图像描述

name of your files doesn't matter in fact, you can rename dimens.xml to anything.xml .实际上,文件名并不重要,您可以将dimens.xml重命名为anything.xml Or you can have dimen_activity.xml and dimen_fragment.xml files, which helps you manage them.或者您可以拥有dimen_activity.xmldimen_fragment.xml文件,这有助于您管理它们。 Also, you can keep in this file <dimen tags, but also <integer s and any other (eg you can have one sizes.xml file).此外,您可以在此文件中保留<dimen标签,还可以保留<integer s 和任何其他标签(例如,您可以拥有一个sizes.xml文件)。 Resources are built upon content inside all XML files placed in values , a kind-of map is created then and all <dimen s from all XML files are available under @dimen/ or R.dimen.资源建立在values中所有 XML 文件中的内容之上,然后创建一种 map 并且所有 XML 文件中的所有<dimen dimen 都可以在@dimen/R.dimen.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM