间与差异QUOT; @ ID /"和" @ + ID /" Android中差异、QUOT、Android、ID

2023-09-11 10:39:34 作者:憇

之间有什么diffirence的 @id / @ + / ID

What is the diffirence between the @id/ and @+/id?

由于在 @ + ID / :+(加号)符号表示,我们正在创造新的资源名称,它必须是创建并加入 R.java 文件,但怎么样的 @id / ?由于从 标识的文件 引用一个Android资源ID时,你不需要加符号,但必须加上Android包名称空间,像这样:

As in the @+id/ : The + (plus) symbol indicates that we are creating the new resource name and it must be created and added in to our R.java file but what about the @id/? As from the documentation of ID when referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so:

android:id="@android:id/list"

但在下面的图片日食忽略了最低暗示我什么样的的@android:ID /

@id / @android:ID 一样吗?

我真的AP preciate你的任何想法有一个精心制作的例子。

I would really appreciate any of your ideas with an elaborate example.

推荐答案

您参考安卓资源,这是在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 myTextViewif it is written after the element you're using it in.