2012-03-31 2 views
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> 

외부 레이아웃 : 또한

<include layout="@layout/inner_layout" /> 

참조 : 기본적으로이 같은 the <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="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> 

답변