Android:将xml包含在其他xml中

Xet*_*xyc 23 xml android android-xml

如何将xml数据包含到其他xml数据中

我有一个标题xml文件为我的应用程序我想在我的特殊其他内容使用xmls有没有办法将标题包含在我的内容中?

Axe*_*cia 32

使用include标签

<?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>
Run Code Online (Sandbox Code Playgroud)


Pip*_*nas 12

您必须使用<merge>标记声明"body"xml布局,以在主要布局上使用<include>标记.

<?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>
Run Code Online (Sandbox Code Playgroud)

这是<include>标记的内容


woo*_*shy 5

您应该使用<include>标记:重新使用布局