Parse the use of include tags 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, the code is redundant and the readability is poor, therefore, we can write code with the same layout into a single module, and then use the <include/> label to reuse the layout code.
App_title.xml:
Copy codeThe Code is as follows: <? 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 = "true" 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:
Copy codeThe Code is as follows: <? 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/theWholeLinearLayout" 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_width = "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 will be 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>

<TableRow>
<TextView android: id = "@ + id/hyperlink name" android: text = "@ string/character name" style = "@ style/StyleTextInfo1" mce_style = "@ style/StyleTextInfo1"/>
<Spinner android: id = "@ + id/departNameS" android: layout_width = "fill_parent" android: layout_height = "wrap_content"/>
</TableRow>

<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>

<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>

<TableRow>
<TextView 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>

<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: id = "@ + id/comatrix 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/comatrix WD" android: text = "@ string/ycUserAcc" style = "@ style/StyleTextInfo1" mce_style = "@ style/StyleTextInfo1"/>
</LinearLayout>
</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: 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>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>

App_bottom.xml:
Copy codeThe Code is as follows: <? 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" android: 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 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"/>
</LinearLayout>
</LinearLayout>

Tradelogin_portrait.xml:
Copy codeThe Code is as follows: <? 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 is set in the include tag (android: id), the id attribute in the referenced layout does not work. It is suspected that the referenced layout outer layer contains an include tag.
Or overwrite the property 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 previous layout cannot
Call the layout id following it. 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>

The effect is as follows:

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.