Android Layout中使用include標籤實現UI佈局重用

 
   
Android Layout中使用include標籤實現UI佈局重用  
1、創建一個獨立的佈局文件作爲共享佈局,common_layout.xml  
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout  
  xmlns:android="http://schemas.android.com/apk/res/android"  
  android:layout_width="wrap_content"  
  android:layout_height="wrap_content">  
  <TextView  
   android:layout_width="wrap_content"  
   android:layout_height="wrap_content"  
   android:text="這是一個共享的佈局文件"  
   />  
</LinearLayout>
2、在主佈局中使用標籤進行包含
<?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" >  
    <include layout="@layout/common_layout"></include>  
</LinearLayout>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章