Android: include a xml into an other xml

Xetoxyc picture Xetoxyc · Jun 10, 2011 · Viewed 26.9k times · Source

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 header into my content?

Answer

Axel M. Garcia picture Axel M. Garcia · Jun 10, 2011

use include tag

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"     
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >
  <!-- Header -->
  <include
    android: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" //Name of the xml layout file you want to include
    />     

...

</RelativeLayout>