如何在<include>标记内链接子视图?</include>

时间:2011-03-17 07:01:41

标签: android include views children

下面的

是从And Dev。

复制的片段
<com.android.launcher.Workspace
android:id="@+id/workspace"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

launcher:defaultScreen="1">

<include android:id="@+id/cell1" layout="@layout/workspace_screen" />
<include android:id="@+id/cell2" layout="@layout/workspace_screen" />
<include android:id="@+id/cell3" layout="@layout/workspace_screen" />

</com.android.launcher.Workspace>

这里他们演示了如何覆盖所包含布局的根视图或ViewGroup的ID。

我的问题是,是否也可以通过XML覆盖孩子的ID? 如果没有,我应该如何链接cell2或cell3的子视图,如果他们的ID已经预设了? HierarchyViewer告诉我所有包含的子视图的属性不会改变,包括ID属性,因此生成具有相同ID的多个视图。

1 个答案:

答案 0 :(得分:1)

匹配id没有错。例如,你如何实现列表视图项?

您可以使用嵌套的findViewById()来访问所需的子视图。

findViewById(CELL3).findViewById(child_View_id)