[Android] Android Layout Optimization & lt; include/& gt;, androidinclude

Source: Internet
Author: User

[Android] Android layout optimization <include/> and androidinclude

 

Reprint please mark: Reproduced in http://www.cnblogs.com/Liuyt-61/p/6602891.html

Bytes -------------------------------------------------------------------------------------------

> Reusable components are extracted and used using the include tag.

Purpose: extract the common components and place them in an xml file separately. Then, use the include label to import them to the public layout.

Effect: Improves the UI production and reuse efficiency, and ensures a more regular and easy-to-maintain UI layout.

Eg: <include layout = "@ layout/common_title"/>

Common_title.xml <? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: background = "#000000" android: paddingBottom = "10dp" android: paddingTop = "10dp"> <TextView android: id = "@ + id/re" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentLeft = "true" android: layout_centerVert Ical = "true" android: layout_marginLeft = "10dp" android: text = "back" android: textColor = "# ffffff" android: textSize = "14sp"/> <TextView android: id = "@ + id/title" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_centerInParent = "true" android: text = "layout optimization" android: textColor = "# ffffff" android: textSize = "18sp"/> <TextView android: id = "@ + id/fun" android: layout_width = "wrap_cont Ent "android: layout_height =" wrap_content "android: layout_alignParentRight =" true "android: layout_centerVertical =" true "android: layout_marginRight =" 10dp "android: text =" function "android: textColor = "# ffffff" android: textSize = "14sp"/> </RelativeLayout> -------------------------------------- main. xml <? 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"> <include layout = "@ layout/common_title"/> </LinearLayout>

 

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.