Reputation: 30132
Given an XML layout (call it the "inner" layout), how do you refer to that inner layout from another custom XML layout (call it the "outer" layout)? Is this possible using XML alone, or are the only solutions programmatic?
Inner layout:
<?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="wrap_content"
android:padding="6dip"
>
<ImageView
android:id="@+id/productImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="6dip"
/>
<TextView
android:id="@+id/productName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/productImage"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</RelativeLayout>
Outer layout:
<?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="wrap_content"
>
<!-- Embed inner XML layout here -->
<Button
android:id="@+id/productButtonAddToShoppingList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="<!-- refer to inner layout -->"
android:layout_marginTop="2dip"
android:text="add to shopping list"
/>
</RelativeLayout>
Upvotes: 1
Views: 417
Reputation: 387667
Basically you use the <include /> tag like this:
<include layout="@layout/inner_layout" />
See also: http://developer.android.com/resources/articles/layout-tricks-reuse.html
Upvotes: 3