Android growth diary-android layout optimization

Source: Internet
Author: User

Android Common layout

1. LinearLayout (Linear layout)

2. Relativelayout (relative layout)

3. tablelayout (Table layout)

4. Absolutelayou (Absolute layout)

5. Framelayout (Frame layout)

Low--------------consumption------------------à high

4->3->5->1->2

Android Layout principles

(1) Use LinearLayout and relativelayout as much as possible, do not use Absolutelayout

(2) In the same layout level, it is recommended to use LinearLayout instead of relativelayout, because LinearLayout performance is slightly higher

(3) Extracting reusable components and using the Include notes

(4) Use the viewstub tag to load some infrequently used layouts

(5) Reduce nesting levels of layouts with merge notes

Eg:

(a) Use of <include/>

Role: Extract common components out of a single XML file, then import the common layout using the include tag

Effect: Improve UI authoring and reuse efficiency, and make UI layouts more structured and maintainable

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

Introduce the same layout in the layout file.

(ii) Merge UI layouts with merge

What it does: Merge UI layouts that reduce the nesting level of the UI layout

Scenario: 1. Layout root node is framelayout and does not need to set properties such as background or padding, you can use merge instead

2. When a layout is used as a sub-layout by another layout include, use merge as the top node of the layout so that the top node is automatically ignored when it is introduced.

(iii) Lazy loading using viewstub

Role: The viewstub tag can be used as an include tag to introduce an external layout, but the layout introduced by Viewstub does not expand by default, does not occupy the display and does not occupy the location, thus saving CPU and memory when parsing layout

Android growth diary-android layout optimization

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.