如何链接内的子视图标签?
下面是从 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>
在这里,他们演示了如何覆盖所包含布局的根 View 或 ViewGroup 的 ID。
我的问题是,是否也可以通过XML覆盖孩子的ID?
如果没有,如果 cell2 或 cell3 的 ID 已经预设,我该如何链接它们的子视图? HierarchyViewer 告诉我,所有包含的子视图的属性都不会改变,包括 ID 属性,从而生成具有相同 ID 的多个视图。
below is a snippet copied from 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>
Here they demonstrate how to overwrite the ID of the root View or ViewGroup of the included layout.
My question is, is it also possible to overwrite the children's ID through XML?
If not, how am I supposed to link cell2 or cell3's children Views if their IDs were already preset? HierarchyViewer tells me that all included children Views' attributes do not change, including the ID attribute, thus generating multiple Views with the SAME ID.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
匹配id没有问题。例如,您还如何实现列表视图项目?
您可以使用嵌套的 findViewById() 来访问所需的子视图。
findViewById(cell3).findViewById(child_View_id)
There is nothing wrong in matching id's. How else would you implement list view items for example?
You can access children views you need by using nested findViewById().
findViewById(cell3).findViewById(child_View_id)