Simple example of <merge> and <include> usage in Android XML-layouts
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>
Take an example:
I have two tags <EditText>
and <ListView >
coming more than one UIs.So I created an XML file as given below to include in all such UI's.
<?xml ...><EditText ... /><ListView ... />
The above XML is not valid XML since it did not have a root element.So a root element is needed just for the sake of XML. <merge>
is the solution as given below:
<?xml ...><merge xmlns:android="http://schemas.android.com/apk/res/android"> <EditText ... /> <ListView ... /></merge>