2011-06-10 91 views
22

如何包含XML數據轉換成其他XML數據安卓:包括XML到其他XML

我有一個頭的XML文件爲我的應用至極,我想在我的特殊其他內容個XML使用 是有什麼方法可以將標題添加到我的內容中?

回答

29

使用包括標籤

<?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> 
+0

它與RelativeLayout的工作嗎? – Xetoxyc 2011-06-10 13:25:34

+0

我還沒有嘗試過使用RelativeLayout,但它應該。可能你必須在include標籤中設置設置放置位置的屬性:android:layout_above,android:layout_toLeftOf等... – 2011-06-10 13:34:16

+0

它不爲我工作與實際佈局可能我的錯誤是其他地方生病的帖子我的代碼 – Xetoxyc 2011-06-10 13:38:46

11

你有一個<合併申報你的「身體」 XML佈局>標籤來使用<包括>標籤您的主要佈局。

<?xml version="1.0" encoding="utf-8"?> 
<merge> 
    <ImageView android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scaleType="center" 
     android:src="@drawable/image"/> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal|bottom" 
     android:background="#AA000000" 
     android:textColor="#ffffffff" 
     android:text="Some Text"/> 
</merge> 

這是你<的內容包括>標籤