Android在xml文件中可使用include包含其他定义好的布局,
可以将多处用到的布局单独出来,然后用include包含进来
下面是一个简单的示例,两个xml文件:
main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:id="@+id/main1"
layout="@layout/sublayout" />
<include
android:id="@+id/main2"
layout="@layout/sublayout" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" Start Another Activity " />
</LinearLayout>
sublayout.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#505050"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="SubLayout" />
<Button
android:id="@+id/mybutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" A Button " />
</LinearLayout>