xml文件中使用include:
不管include几次,都只相当于include一次。
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <Button
- android:text="@+id/Button01"
- android:id="@+id/Button01"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </Button>
- <Button
- android:text="@+id/Button01"
- android:id="@+id/Button02"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- </Button>
- </LinearLayout>
接下来在main.xml文件中将其include进来,如下
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/hello"
- />
- <include layout="@layout/son"/>
- </LinearLayout>