Android:将XML包括在另一个XML中
-
26-10-2019 - |
题
如何将XML数据包括在其他XML数据中
我有一个标题XML文件,用于我的应用程序,我想在我的其他内容xmls中使用,是否有一种方法可以将标题包含在我的内容中?
解决方案
使用包括标签
<?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>
其他提示
您必须使用<merge>标签声明您的“车身” XML布局,以便在主体布局上使用<apply>标签。
<?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>
这是您的<cludland>标签的内容
您应该使用<include>标签: 重新使用布局
不隶属于 StackOverflow