Skip to content Skip to sidebar Skip to footer

Android: Include A Xml Into An Other Xml

How to include a xml data into an other xml data? I have a header xml-file for my application which I want to use in my special other content xmls. Is there a ways to include the h

Solution 1:

use include tag

<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"
 ><!-- Header --><includeandroid:id="@+id/container_header_lyt"android:layout_height="wrap_content"android:layout_width="fill_parent"android:layout_above=...android:layout_toLeftOf=...layout="@layout/header_logo_lyt" //Nameofthexmllayoutfileyouwanttoinclude
    />     

...

</RelativeLayout>

Solution 2:

You have to declare your "body" xml layout with a < merge > tag to use < include > tag on your principal layout.

<?xml version="1.0" encoding="utf-8"?><merge><ImageViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:scaleType="center"android:src="@drawable/image" / ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal|bottom"android:background="#AA000000"android:textColor="#ffffffff"android:text="Some Text" / ></merge>

This is the content of your < include > tag

Solution 3:

You should use < include > tag: Re-using Layouts with

Post a Comment for "Android: Include A Xml Into An Other Xml"