In the layout optimization, Androi's official mentions these three kinds of layout <include/>, <merge/>, <viewstub/>, and describes the advantages of each of the three layouts, the following is a brief talk about their advantages, and how to use , simply review.
1. Layout Reuse <include/>
<include/> Tags can reuse layout files, simple to use as follows:
<span style= "FONT-SIZE:12PX;" ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:orientation= " Vertical " android:layout_width=" match_parent " android:layout_height=" Match_parent " android: background= "@color/app_bg" android:gravity= "Center_horizontal" > <include layout= "@layout/titlebar "/> ... </LinearLayout> </span>
Description: 1) The <include/> Tag can use a separate layout property, which is also required.
2) can use other properties. <include/> id Span style= "padding:0px; margin:0px; Line-height:28px "" And your layout id your layout id will be overwritten with the solution.
3) in include label all android:layout_* layout_width and layout_height two properties
4) A layout can contain two identical include tags.
2. Reduce the view level <merge/>
<merge/> tags play a very important role in the structural optimization of the UI, which can be used to prune unnecessary layers and optimize the UI. <merge/> more for replacing Framelay out or When one layout contains another, <MERGE/> Slow down your UI performance. You can use the <merge/> label optimization.
<span style= "FONT-SIZE:12PX;" ><merge xmlns:android= "Http://schemas.android.com/apk/res/android" > <button android:layout_ Width= "Fill_parent" android:layout_height= "wrap_content" android:text= "@string/add"/> < Button android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "@ String/delete "/> </merge> </span>
more <merge/> Introduction can refer to click to open the link
3. Use <viewstub/> when needed
The biggest advantage of the <viewstub/> tag is that it does not load when you need it, and it doesn't affect performance when the UI is initialized. A variety of infrequently used layouts like progress bars, display error messages, and so on can use <viewstub/> tags to reduce memory usage and speed rendering. <viewstub/> is an invisible, 0 - size View. <viewstub/> Tags are used as follows:
<span style= "FONT-SIZE:12PX;" ><viewstub android:id= "@+id/stub_import" android:inflatedid= "@+id/panel_import" android: layout= "@layout/progress_overlay" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content " android:layout_gravity=" bottom "/> </span>
Description
when callingInflate ()function,viewstubThe referenced resource is substituted and returns the referencedView. This program can be directly referenced by theViewWithout having to call the function againFindviewbyid ()
viewstub now, there's a flaw that doesn't support it . <merge/> tags.
More <viewstub/> Label Introduction can be consulted: Click to open the link
Android layout include, merge, Viewstub