yan*_*nko 96
some_activity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    // some views
    <include layout="@layout/view_part"/>
   // probably more views
</LinearLayout>
view_part.xml:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    // the views to be merged
</merge>
举个例子:
我有两个标签,<EditText>并且<ListView >有不止一个 UI。因此,我创建了一个如下所示的 XML 文件以包含在所有此类 UI 中。
<?xml ...>
<EditText ... />
<ListView ... />   
上述 XML 不是有效的 XML,因为它没有根元素。所以为了 XML 需要一个根元素。<merge>是下面给出的解决方案:
<?xml ...>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <EditText ... />
    <ListView ... />
</merge>
有一个简单的Android XML布局<include /> HOWTO,它也解释了http://www.coboltforge.com/2012/05/tech-stuff-layout/上常见的陷阱.这可能有帮助......
| 归档时间: | 
 | 
| 查看次数: | 56455 次 | 
| 最近记录: |