android - 包括 XML 布局

标签 android xml layout

我有以下用于 ListView 的工作 xml 布局

<TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text01"/>

<RelativeLayout
        android:id="@+id/rel01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <ImageView
    android:id="@+id/widget01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo"
    />

    <ImageButton
    android:id="@+id/widget02"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/widget01"
    android:src="@drawable/refresh"
    />
</RelativeLayout>

    <ListView 
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <TextView 
        android:id="@+id/android:empty"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        />
</LinearLayout>

我想将text01和所有RelativeLayout移动到另一个文件中(它是我所有 Activity 的标题)并将其包含在此xml中。我正在尝试,但我无法做到这一点,sameone 可以帮助我吗?

最佳答案

您应该将想要重用的内容放入额外的文件中。然后您可以使用以下部分:

<!-- my_header.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/text01"/>

在另一个文件中包含它:

<include layout="@layout/my_header" />
<!-- your other stuff -->

关于android - 包括 XML 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6158201/

相关文章:

android - 如何在不重新启动的情况下自动将保存的文件添加到目录 - Android应用程序

xml - 使用 XSLT 转换 XSLT 时保留实体引用

android - 在代码中将 View 添加到现有的 xml View 组

android - Holo 主题使我的按钮更大

java - Android - 通过 TextView 将文本从一个类传递到另一个类

android - 从 Android 相机拍摄的照片是全黑的

android - 我的 android 应用程序访问 wcf web 服务的命名空间、soap 操作和 url 应该是什么?

xml - 在XSL中执行检查

java - 如何使用 XMLBeans 将 XML 声明添加到 xml

android - 如何将按钮一半放在 cardview 上,一半放在父布局上