Use of the include tag in Android

Source: Internet
Author: User
In a project, we may need to use the same layout design. If they are all written in an XML file, Code The layout code can be reused by using the <include/> label when the code of the same layout is redundant and the readability is poor. App_title.xml: <? XML version = "1.0" encoding = "UTF-8"?> <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"> <textview Android: text = "@ string/login" Android: Id = "@ + ID/Title" Android: textsize = "20px" Android: textcolor = "@ color/White" Android: layout_width = "wrap_content" Android: layout_centerinparent = "tr Ue "Android: layout_height =" wrap_content "/> <button Android: text =" back "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"/> </relativelayout> app_tradelogin.xml: <? XML version = "1.0" encoding = "UTF-8"?> <! -- Android: layout_below and Android: layout_above must be set. Otherwise, the interface is irregular. If Android: layout_above is not set, the interface does not have a sliding effect. --> <scrollview Android: layout_below = "@ + ID/titlelayout" Android: layout_above = "@ + ID/appbottom" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: layout_centerinparent = "true" xmlns: Android = "http://schemas.android.com/apk/res/android"> <linearlayout Android: Id = "@ + ID/thewholelinearla Yout "Android: Orientation =" vertical "Android: layout_width =" fill_parent "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"> <tablelayout Android: Id = "@ + ID/widget43" Android: layout_w Idth = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical" xmlns: Android = "http://schemas.android.com/apk/res/android" Android: stretchcolumns = "1"> <tablerow> <! -- Reference the defined textview style. If the attributes are the same as those defined in the style, the attributes defined in the style are replaced here --> <textview Android: id = "@ + ID/tradername" Android: TEXT = "@ string/tradername" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> <spinner Android: id = "@ + ID/tradernames" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> </spinner> </tablerow> <textview Android: id = "@ + ID/hyperlink name" Android: text = "@ strin G/customization name "style =" @ style/styletextinfo1 "mce_style =" @ style/styletextinfo1 "/> <spinner Android: Id =" @ + ID/departnames "Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"/> </tablerow> <textview Android: Id = "@ + ID/strcomponyname" Android: TEXT = "@ string/acctype" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> <spinner Android: id = "@ + ID/acctyte" Android: Layout_width = "fill_parent" Android: layout_height = "wrap_content"/> </tablerow> <textview Android: Id = "@ + ID/struseracc" Android: TEXT = "@ string/useracc" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> <edittext Android: id = "@ + ID/accedittext" Android: text = "" Android: numeric = "decimal" style = "@ style/styleedittext1" mce_style = "@ style/styleedittext1"/> </tablerow> <t Extview Android: Id = "@ + ID/userpwd" Android: TEXT = "@ string/userpwd" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> <edittext Android: id = "@ + ID/userpwdet" Android: text = "" Android: password = "true" style = "@ style/styleedittext1" mce_style = "@ style/styleedittext1"/> </tablerow> <textview Android: id = "@ + ID/comatrix WD" Android: text = "@ string/comatrix WD" style = "@ style/styletextinfo1" MCE _ Style = "@ style/styletextinfo1"/> <edittext Android: Id = "@ + ID/comatrix wdet" Android: text = "" Android: password = "true" style = "@ style/styleedittext1" mce_style = "@ style/styleedittext1"/> </tablerow> </tablelayout> </linearlayout> <linearlayout Android: orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"> <linearlayout Android: Id = "@ + ID/linearlayouttab1" Android: Layout _ Height = "wrap_content" Android: layout_width = "fill_parent" Android: Orientation = "horizontal"> <linearlayout Android: Id = "@ + ID/linearlayouttab2" Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: Orientation = "horizontal" Android: layout_weight = "1"> <checkbox Android: id = "@ + ID/recordacc" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content"/> <textview android Oid: Id = "@ + ID/commp WD" Android: TEXT = "@ string/saveuseracc" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> </linearlayout> <linearlayout Android: id = "@ + ID/linearlayouttab2" Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: Orientation = "horizontal" Android: layout_weight = "1"> <checkbox Android: Id = "@ + ID/hideacc" Android: layout_width = "wrap_content" Android: Layout_height = "wrap_content"/> <textview Android: Id = "@ + ID/commp WD" Android: TEXT = "@ string/ycuseracc" style = "@ style/styletextinfo1" mce_style = "@ style/styletextinfo1"/> </linearlayout> <linearlayout Android: id = "@ + ID/linearlayouttab1" Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: Orientation = "horizontal"> <linearlayout Android: layout_width = "220px" android Oid: layout_height = "wrap_content" Android: Orientation = "horizontal" Android: gravity = "center"> <button Android: Id = "@ + ID/confirmexch" Android: gravity = "center" Android: layout_width = "wrap_content" 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"/> </Linearlayout> <linearlayout Android: Id = "@ + ID/linearlayouttab" Android: layout_height = "wrap_content" Android: layout_width = "fill_parent" Android: gravity = "center"> <imageview Android: layout_width = "wrap_content" Android: layout_height = "50px" Android: id = "@ + ID/myimage"/> </linearlayout> </scrollview> app_bottom.xml: <? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout Android: Id = "@ + ID/appbottom" Android: Orientation = "vertical" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: layout_alignparentbottom = "true" xmlns: Android = "http://schemas.android.com/apk/res/android"> <linearlayout Android: Orientation = "horizontal" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: background = "@ drawable/Light"> <Imageview Android: Id = "@ + ID/about" Android: layout_width = "30px" Android: layout_height = "wrap_content" Android: src = "@ drawable/TTT" Android: layout_alignparentleft = "true"/> <textview Android: Id = "@ + ID/Light" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: textcolor = "@ color/Black"/> </linearlayout> <linearlayout Android: Orientation = "horizontal" Android: layout_width = "fill _ Parent "Android: layout_height =" wrap_content "Android: Background =" @ drawable/mainmenu "> <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"/> <button Android: Id = "@ + ID/entrustbutton" Android: layout_weight = "1" Android: layout_width = "52px" Droid: layout_height = "wrap_content" Android: textcolor = "@ color/White" Android: text = "" Android: Background = "@ drawable/button1"/> <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"/> <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"/> <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"/> <button androi D: 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"/> </linearlayout> tradelogin_portrait.xml: <? XML version = "1.0" encoding = "UTF-8"?> <Relativelayout Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" style = "@ style/stylelayoutmain" mce_style = "@ style/stylelayoutmain" xmlns: android = "http://schemas.android.com/apk/res/android"> <! -- The relativelayout attribute cannot be set in the include label, for example, Android: layout_alignparentbottom, because it does not work --> <! -- After the ID attribute (Android: ID) is set in the include label, the ID attribute in the referenced layout does not work, it is suspected that the outer layer of the referenced layout contains an include tag or overwrites its attribute id --> <! -- If there is no include tag, all the layout code is written in an XML file, and the interface looks redundant and has poor readability. In addition, the interface is loaded in order, and the layout ID behind the interface cannot be called in the previous layout. After using include, an include can reference the layout ID attribute in the later include --> <include Android: id = "@ ID/titlelayout" layout = "@ layout/app_title"/> <include layout = "@ layout/app_tradelogin"/> <include layout = "@ layout/app_bottom" /> </relativelayout>
Related Article

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.