Merge two layout xml in android

By | June 26, 2011

Merging layout is an excellent feature in android. Separate xml can be included in a single xml.

For this first i create a main.xml file

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

 <TextView
	android:text="Account"
	android:id="@+id/account"
	android:layout_below="@+id/title"
	 android:padding="10dip"
	android:layout_alignParentLeft="true"
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	>
</TextView>
<EditText
	android:id="@+id/youtube_feed_TF"
	android:hint="Username"
	android:layout_marginLeft="10dip"
	android:inputType="textEmailAddress"
	android:layout_below="@+id/account"
	android:layout_centerHorizontal="true"
	android:layout_width="fill_parent"
	android:padding="10dip"
	android:layout_height="wrap_content"
></EditText>
<include layout="@layout/footer2button"/>

</RelativeLayout>

In the bottom you can see that i have included a xml file named footer2button.xml

<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
	android:layout_width="fill_parent"
	android:gravity="bottom"
	android:id="@+id/bottomlayout"
	android:layout_height="wrap_content"
	android:layout_alignParentBottom="true">

			<Button android:layout_height="wrap_content"
				 android:id="@+id/backbutton"
				 android:text="Back"
				 android:layout_width="wrap_content"
				 android:layout_weight="1"
				 android:layout_alignParentBottom="true">
			</Button>

			<Button android:layout_height="wrap_content"
				android:id="@+id/nextbutton"
				 android:text="Next"
				 android:layout_width="wrap_content"
				 android:layout_weight="1"
				 android:layout_alignParentBottom="true">
		   </Button>

</LinearLayout>
</merge>

The Merged layout will be like this

8 thoughts on “Merge two layout xml in android

  1. Pingback: Merge two layout xml in android | Coderz Heaven | Content Store

  2. Pingback: Android » Archive » Merge two layout xml in android | Coderz Heaven » Android

  3. Pingback: Merge two layout xml in android | Coderz Heaven

  4. Pingback: Merge two layout xml in android | Coderz Heaven | WWW.ANDROIDWORLD.BIZ

  5. Pingback: Merge two layout xml in android | Coderz Heaven | Dr-Net

  6. Bayanaa

    Hello there
    I followed your tutorials.
    But footer2button.xml comes up new windows how to fix it?

    Reply

Leave a Reply to James Cancel reply

Your email address will not be published. Required fields are marked *