>当Android将android:id
描述为:
资源 ID。此可绘制对象的唯一资源 ID。若要为此项创建新的资源 ID,请使用以下格式:"@+id/name"。加号表示应将其创建为新 ID。
什么时候id
不会被创建为新id
?这难道不应该暗示吗?
布局文件中的视图可以引用其他视图。当使用 RelativeLayout 或 ConstraintLayout 时,这种情况经常发生,因为 ConstraintLayout 需要在其子级之间形成显式关系。
例如
<Button android:id="@+id/progress" />
<Button
android:id="@+id/next"
app:layout_constraintTop_toBottomOf="@id/progress" />
指定对另一个视图的引用时,会省略+
,因为我们不是在创建 ID,而是引用现有 ID。