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

发布于 2025-01-12 10:21:24 字数 325 浏览 2 评论 0 原文

我在 android studio 项目中创建了一个新的值资源文件,名称为 dimens 但是在从 XML 引用它时,我必须使用属性 @dimen

我真的很好奇,想知道引用标签必须与文件名相同,但事实并非如此。

我在字符串和颜色中看到了相同的模式。

但事情就是这样吗?有什么线索吗?

输入图片此处描述

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

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.

But it is like that? any clue?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2025-01-19 10:21:24

事实上,文件的名称并不重要,您可以将 dimens.xml 重命名为 anything.xml。或者,您可以拥有 dimen_activity.xmldimen_fragment.xml 文件,这有助于您管理它们。另外,您可以在此文件中保留 标签,还可以保留 和任何其他标签(例如,您可以拥有一个 sizes.xml 文件)。资源基于放置在 values 中的所有 XML 文件内的内容构建,然后创建一种映射,并且所有 XML 文件中的所有 都可以在 下使用>@dimen/R.dimen.

name of your files doesn't matter in fact, you can rename dimens.xml to anything.xml. Or you can have dimen_activity.xml and dimen_fragment.xml files, which helps you manage them. Also, you can keep in this file <dimen tags, but also <integers and any other (e.g. you can have one sizes.xml file). Resources are built upon content inside all XML files placed in values, a kind-of map is created then and all <dimens from all XML files are available under @dimen/ or R.dimen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文