1

可能重复:
Android中“@id/”和“@+id/”的区别

在为 Android 应用程序创建布局 XML 文件时,通常将每个布局元素的 ID 声明为:

@+id/elementID

不是吗?我猜“+”表示这个元素的 ID 是刚刚创建的,因此您需要加号,对吗?

但是,当您在创建布局元素之前引用它时,您需要做什么?你是用“+”引用它,然后在没有“+”的情况下创建它吗?简单地说,以下代码是否正确(在 RelativeLayout 容器中)?

<ImageButton
    android:id="@+id/helpButton"
    android:layout_toLeftOf="@+id/moreButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
<ImageButton
    android:id="@id/moreButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" />
4

1 回答 1

2

I guess the "+" means that this element's ID is just created and therefore you need the plus, right?

Yes.

Do you refer to it with "+" and then create it without "+"?

Yes. The first occurrence of the ID gets the +. Second and subsequent occurrences can leave it off.

Simply put, is the following code correct (in a RelativeLayout container)?

Well, your ImageButtons are missing images... :-)

That being said, your use of the + sign there seems fine.

于 2012-06-02T17:44:33.083 回答