The purpose of this Code is to improve the reusability of the Code. It can regard a defined layout as an element of another layout.
The following is an example:
This is 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" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /><include layout="@layout/include1"/><include layout="@layout/include2"/></LinearLayout>
Include1.xml
<? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: text = "This is the first layout file! "Android: layout_width =" wrap_content "Android: layout_height =" wrap_content "> </textview>
Include2.xml
<? XML version = "1.0" encoding = "UTF-8"?> <Textview xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "match_parent" Android: layout_height = "match_parent" Android: text = "This is the first layout file"> </textview>
Note: The following two layout files are included in Main. xml. You can see the effect without adding other code in activity. java.