1
給定一個XML layout(稱之爲「內部」佈局),如何引用另一個自定義XML佈局的內部佈局(稱之爲「外部」佈局)?這是可能單獨使用XML,還是唯一的編程解決方案?如何從另一個自定義XML佈局引用自定義XML佈局?
內部佈局:
<?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>
外佈局:
<?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>