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