Use of include tags in android

Source: Internet
Author: User

In a project we may need to use the same layout design, if it is written in an XML file, the code is very redundant, and very poor readability, so we can put the same layout of the code to write a separate module, and then use the time can be <include/> Label to reuse the layout code. App_title.xml: 01<?xml version= "1.0" encoding= "Utf-8"? >02<relativelayout android:id= "@+id/ Titlelayout "android:layout_width=" fill_parent "android:layout_height=" wrap_content "  android:background=" @drawable/bt "xmlns:android=" http://schemas.android.com/apk/res/android ">04    05  <textview android:text= "@string/login" android:id= "@+id/title" android:textsize= "20px" android:textcolor= "@color/white" 06   android:layout_width= "Wrap_content" android:layout_centerinparent= "true" android:layout_height= "Wrap_ Content "/>  07  <button android:text=" return "android:id=" @+id/refresh "android:layout_width=" Wrap_ Content "android:layout_height=" wrap_content "  android:layout_alignparentright=" true "android:focusable=" False "android:textcolor=" @color/white "  android:background=" @drawable/okbutton "Android:layout_marginright= "3px"/>10</relativelayout>app_tradelogin.xml: 01<?xml version= "1.0" encoding= "Utf-8 "?>02<!--Android:layout_below and Android:layout_above must be set, otherwise the interface is irregular, not set android:layout_above This interface does not have a sliding effect-- 03<scrollview android:layout_below= "@+id/titlelayout" android:layout_above= "@+id/appbottom" Android:layout_ Width= "Fill_parent"  04  android:layout_height= "Fill_parent" android:layout_centerinparent= "true" xmlns: Android= "Http://schemas.android.com/apk/res/android" >05 <linearlayout android:id= "@+id/ Thewholelinearlayout "android:orientation=" vertical "android:layout_width=" fill_parent " 06  android: layout_height= "Wrap_content" android:paddingleft= "10px" android:paddingtop= "6px" android:paddingright= "10px" >  <linearlayout android:id= "@+id/linearlayoutleft" android:orientation= "vertical" android:layout_width= " Fill_parent "android:layout_height=" wrap_content ">08   <tablelayout android:id=" @+id/widget43 "Android: Layout_wiDth= "fill_parent"    android:layout_height= "fill_parent" android:orientation= "vertical"     Xmlns:android= "Http://schemas.android.com/apk/res/android" android:stretchcolumns= "1" >11    < TableRow > 12    <!--  referencing a defined TextView style, if the properties and properties defined in the style are duplicated, the attributes defined in the style are replaced-->13     <textview android:id= "@+id/tradername" android:text= "@string/tradername" mce_/>14     < Spinner android:id= "@+id/tradernames" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" >     </spinner>16    </tablerow>17      18    <tablerow >19     <textview android:id= "@+id/departname" android:text= "@string/departname" mce_/>20   & nbsp <spinner android:id= "@+id/departnames" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" />21    </tablerow>22     23    <taBlerow >24     <textview android:id= "@+id/strcomponyname" android:text= "@string/acctype" Mce_/>25 & nbsp   <spinner android:id= "@+id/acctyte" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content "/>26    </tablerow>27     28    <tablerow >29     & Lt TextView android:id= "@+id/struseracc" android:text= "@string/useracc" mce_/>30     <edittext android: Id= "@+id/accedittext" android:text= "" android:numeric= "decimal" mc_/>31    </tablerow>32     33    <tablerow >34     <textview android:id= "@+id/userpwd" android:text= "@ String/userpwd "mce_/>35     <edittext android:id=" @+id/userpwdet "android:text=" "android:password=" True "mce_/>36    </tablerow>37     38    <tablerow >39     & Lt TextView android:id= "@+id/commpwd" android:text= "@string/COmmpwd "mce_/>40     <edittext android:id=" @+id/commpwdet "android:text=" "android:password=" true "MCE _/>41    </tablerow>42   </tablelayout>43  </linearlayout>44   45  <linearlayout android:orientation= "vertical" android:layout_width= "fill_parent" android:layout_height= " Wrap_content ">46    47    <linearlayout android:id=" @+id/linearlayouttab1 "Android:layout_ height= "Wrap_content"  48     android:layout_width= "fill_parent" android:orientation= "Horizontal" >49      50     <linearlayout android:id= "@+id/linearlayouttab2" android:layout_height= "Wrap_content"  51      android:layout_width= "fill_parent" android:orientation= "Horizontal" android:layout_weight= "1" >52      <checkbox android:id= "@+id/recordacc"  android:layout_ Width= "Wrap_content" android:layout_height= "wrap_content"/>53     &NBSP;<textview android:id= "@+id/commpwd" android:text= "@string/saveuseracc" mce_/>54     </ linearlayout> 55     <linearlayout android:id= "@+id/linearlayouttab2" android:layout_height= " Wrap_content " 56      android:layout_width=" fill_parent "android:orientation=" Horizontal " android:layout_weight= "1" >57       58      <checkbox android:id= "@+id/ Hideacc "android:layout_width=" wrap_content "android:layout_height=" wrap_content "/>59      < TextView android:id= "@+id/commpwd" android:text= "@string/ycuseracc" mce_/>60     </LinearLayout> & nbsp;61    </linearlayout>62     63   <linearlayout android:id= "@+id/ LinearLayoutTab1 "android:layout_height=" wrap_content " 64     android:layout_width=" Fill_parent " android:orientation= "Horizontal" >65    66     <linearlayout android:layout_width= "220px "android:layout_height=" wrap_content "android:orientation=" horizontal " 67      android: gravity= "center" >68              69               <button android:id= "@+id/confirmexch" android:gravity= "center" android:layout_width= "Wrap_content"  70         android:layout_height= "50px" android:textsize= "22DP" android:text= "@string/login" Android : layout_weight= "1"         android:focusable= "false" android:textcolor= "@color/white" Android: background= "@drawable/buttonl"/>72     </linearlayout>73     74     < LinearLayout android:id= "@+id/linearlayouttab" android:layout_height= "wrap_content"  75       Android:layout_width= "fill_parent" android:gravity= "center" >76      <imageview Android:layout_ Width= "Wrap_content" android:layout_height= "50px" android:id= "@+id/myimage"/&Gt;77     </linearlayout>78  </linearlayout>79 </linearlayout>80 </LinearLayout >81</scrollview>app_bottom.xml: 01<?xml version= "1.0" encoding= "Utf-8"? >02<linearlayout Android:id= "@+id/appbottom" android:orientation= "vertical" android:layout_width= "fill_parent"  03   android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true"  xmlns:android= "/http Schemas.android.com/apk/res/android ">05   06 <linearlayout android:orientation=" Horizontal " Android:layout_width= "Fill_parent"  07  android:layout_height= "wrap_content" android:background= "@ Drawable/light ">08  <imageview  android:id=" @+id/about "android:layout_width=" 30px "android:layout _height= "Wrap_content" android:src= "@drawable/ttt"    android:layout_alignparentleft= "true"/>http ://www.huiyi8.com/webyuanma/10  <textview android:id= "@+id/light" android:layout_width= "Fill_parent" Android:layout_height= "Wrap_content" android:textcolor= "@color/black"/>11 </linearlayout>12  13 < LinearLayout android:orientation= "Horizontal" android:layout_width= "fill_parent"  14  android:layout_ height= "Wrap_content" android:background= "@drawable/mainmenu" >15  <button android:id= "@+id/quotButton" android:layout_weight= "1" android:layout_width= "52px" android:layout_height= "Wrap_content"   Android: Textcolor= "@color/white" android:text= "android:background=" @drawable/button1 "/>17    18  < Button android:id= "@+id/entrustbutton" android:layout_weight= "1" android:layout_width= "52px" android:layout_height = "Wrap_content"   android:textcolor= "@color/white" android:text= "" android:background= "@drawable/button1"/ >20  <button android:id= "@+id/querybutton" android:layout_weight= "1" android:layout_width= "52px" Android : layout_height= "wrap_content"   android:textcolor= "@color/white" android:text= "" android:background= "@Drawable/button1 "/>22    23  <button android:id=" @+id/yinzhengbutton "android:layout_weight=" 1 "Android:layout_width=" 52px "android:layout_height=" wrap_content "  android:textcolor=" @color/white " android:text= "" android:background= "@drawable/button1"/>25    26  <button android:id= "@+id/ Recordbutton "android:layout_weight=" 1 "android:layout_width=" 52px "android:layout_height=" Wrap_content "  Android:textcolor= "@color/white" android:text= "android:background=" @drawable/button1 "/>28    29  <button android:id= "@+id/logoutbutton" android:layout_weight= "1" android:layout_width= "52px" Android: layout_height= "wrap_content"   android:textcolor= "@color/white" android:text= "" android:background= "@ Drawable/button1 "/>31 </LinearLayout> website source code download 32</linearlayout>tradelogin_portrait.xml: view Sourceprint?01<?xml version= "1.0" encoding= "Utf-8"? >02<relativelayout android:layout_width= "Fill_parenT "android:layout_height=" fill_parent "mc_03 xmlns:android=" Http://schemas.android.com/apk/res/android ">04  05 <!--include tags cannot set relativelayout properties, such as Android:layout_alignparentbottom, because it does not work-->06 <!-- After setting the id attribute in the Include tag (ANDROID:ID), the id attribute in its referenced layout layouts does not work, and it is suspected that the layout that it references is wrapped in a layer of include tags  07   Or it overrides its properties. id-->08 <!--If there is no include tag, all layout code is written in an XML file, the interface is very redundant, and the readability is poor. And when the interface is loaded in order, the previous layout cannot be   Call the layout id behind it. With include, you can refer to the Layout ID property of the include in an include-->10 <include android:id= "@id/titlelayout" layout= "@layout/app _title "/>11 <include layout=" @layout/app_tradelogin "/>12   13 <include layout=" @layout/app_ Bottom "/>14  15</RelativeLayout> effects Interface:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.