25

xml データを他の xml データに含める方法は?

特別な他のコンテンツ xml で使用したいアプリケーション用のヘッダー xml ファイルがあります。コンテンツにヘッダーを含める方法はありますか?

4

3 に答える 3

36

インクルードタグを使う

<?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>
于 2011-06-10T13:12:14.600 に答える
12

プリンシパルレイアウトで<include>タグを使用するには、<merge>タグを使用して「body」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>

これは<include>タグの内容です

于 2011-06-10T14:03:12.730 に答える
6

< include > タグを使用する必要があります: Re-using Layouts with

于 2011-06-10T13:11:10.863 に答える