Reputation: 531
I have the following working xml layout for a ListView
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text01"/>
<RelativeLayout
android:id="@+id/rel01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/widget01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"
/>
<ImageButton
android:id="@+id/widget02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/widget01"
android:src="@drawable/refresh"
/>
</RelativeLayout>
<ListView
android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
/>
</LinearLayout>
I want to move text01 and all RelativeLayout in another file (it is the header for all my activities) and include it in this xml. I am trying but I am not able to do this, can sameone help me?
Upvotes: 2
Views: 1075
Reputation: 12292
You should put the things you want to reuse into extra files. Then you can use the parts like:
<!-- my_header.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/text01"/>
In another file include it with:
<include layout="@layout/my_header" />
<!-- your other stuff -->
Upvotes: 3
Reputation: 24181
First : create a new file layout xml : header.xml ; which will contain the TextView and all the RelativeLayout
Second : you can include it where ever you want with the following code :
<include android:id="@+id/myHeader"
layout="@layout/header" />
Upvotes: 0