Merge Optimized layout

Source: Internet
Author: User
<merge/> Tags are used to reduce the level of the View tree to optimize the Android layout for new projects, without the need to change the run after using the "DDMS, Dump View Hierarchy for UI Automator" tool, Get results The bottom two layers relativelayout and TextView are the contents of the Activity_main.xml layout, the framelayout above is the top-level view added by activity Setcontentview. The following using the Merge tab can see the difference only need to change the relativelayout to a merge framelayout below is directly textview, compared with the previous one less than a layer of relativelayout and achieve the same effect. What happens when you consider using the merge label?

One is that, as in the example above, the child view does not need to specify any layout properties for the parent view, in the example TextView just needs to be added directly to the parent view for display on the line.

The other is that if you need to embed a layout (or view) inside the LinearLayout, and the root node of the layout (or view) is also linearlayout, so that there is a layer of unused nesting, it is no doubt that this only slows down the program speed. And at this point, if we use the merge root tag to avoid that problem, the official document Android Layout Tricks #3: Optimize by the example in merging demonstrates this situation.

Note: <merge/> can only be used as the root tag of an XML layout. When you inflate a layout file that begins with <merge/>, you must specify a parent ViewGroup, and you must set Attachtoroot to True.

Merge Optimized layout

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.