我为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移动到另一个文件中(它是我所有活动的标题)并将其包含在此xml中。我正在尝试,但我无法做到这一点,可以帮助我吗?
答案 0 :(得分:3)
您应该将要重复使用的内容放入额外的文件中。然后你可以使用像:
这样的部分<!-- 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 -->
答案 1 :(得分:0)
首先:创建一个新的文件布局xml: header.xml ;它将包含TextView和所有RelativeLayout
第二:您可以使用以下代码将其包含在任何地方:
<include android:id="@+id/myHeader"
layout="@layout/header" />