如果在一个项目中需要用到相同的布局设计,可以通过<include /> 标签来重用layout代码,该标签在android开发文档中没有相关的介绍。在android主屏程序中 用到了这个标签:
01
<com.android.launcher.Workspace
02
android:id="@+id/workspace"
03
android:layout_width="fill_parent"
04
android:layout_height="fill_parent"
05
launcher:defaultScreen="1">
06
<include android:id="@+id/cell1" layout="@layout/workspace_screen" />
07
<include android:id="@+id/cell2" layout="@layout/workspace_screen" />
08
<include android:id="@+id/cell3" layout="@layout/workspace_screen" />
09
10
</com.android.launcher.Workspace>
这样可以多次引用一个布局片段而不用重复的复制、粘贴。通过include标签也可以覆写一些属性的值,例如上面的示例就覆写了引用的layout中的id值。下面是另外一个示例:
1
<include android:layout_width="fill_parent" layout="@layout/image_holder" />
2
<include android:layout_width="256dip" layout="@layout/image_holder" />