我有以下用于 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/