<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- head --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- 引入佈局 也是xml佈局文件--> <include layout="@layout/head"/> </LinearLayout> <!-- 中間 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"> <!-- 引入佈局 也是xml佈局文件--> <include layout="@layout/middle"/> </LinearLayout> <!-- 引入其餘佈局 也是xml佈局文件--> <!-- …… --> <!-- 底部 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <!-- 引入佈局 也是xml佈局文件--> <include layout="@layout/bottom"/> </LinearLayout> </LinearLayout>
先整體佈局,有的佈局能夠分爲幾部分,好比頭部、中部、底部,代碼如上。android
用include layout=""在佈局中引入其餘的佈局,這樣結構就比較清楚,方便佈局模塊化,複用佈局。模塊化
簡單的,能夠直接一個xml文件佈局。佈局