更新时间:2022-06-21 08:48:30
您参考安卓资源
,这是在Android系统已经定义, @android:ID /..
,而在你的项目中创建已定义的接入资源/,可以使用 @id /..
you refer to Android resources
, which are already defined in Android system, with @android:id/..
while to access resources that you have defined/created in your project, you use @id/..
更多信息
按照在聊天你澄清,你说你有一个这样的问题:
As per your clarifications in the chat, you said you have a problem like this :
如果我们使用机器人:ID =@ ID / layout_item_id
这是行不通的。相反 @ + ID /
工作有啥区别就在这里?这是我原来的问题。
If we use
android:id="@id/layout_item_id"
it doesn't work. Instead@+id/
works so what's the difference here? And that was my original question.
嗯,这取决于上下文,当你使用的XML属性机器人:ID
,那么你指定一个新的ID,并指示解析器(或称之为生成器)创建于 R.java
新条目,因此,你必须包括 +
标志。
Well, it depends on the context, when you're using the XML attribute of android:id
, then you're specifying a new id, and are instructing the parser (or call it the builder) to create a new entry in R.java
, thus you have to include a +
sign.
而在其他情况下,如安卓layout_below =@ ID / myTextView
,你指的是已经创建了一个ID,所以解析器链接这在已创建的ID R.java
。
While in the other case, like android:layout_below="@id/myTextView"
, you're referring to an id that has already been created, so parser links this to the already created id in R.java
.
更多信息再次
正如你在聊天说,请注意,安卓layout_below =@ ID / myTextView
将无法识别ID为元素 myTextView
如果你使用它的元素之后写的。
As you said in your chat, note that android:layout_below="@id/myTextView"
won't recognize an element with id myTextView
if it is written after the element you're using it in.