Performance Optimization 1--ui optimization
1. Using the system gives us a few abstract tags
①include: Reusing
The Include Layout property specifies an external layout file that does not have to be repeated in this code.
If the include specifies this attribute for other android:layout_*, then layou_width and layout_height must exist. Otherwise, the other cannot take effect.
②viewstub: Load on Demand
The viewstub tag is similar to the include tag, and is used to load a layout using the Layout property. The difference is that the include tag is used to reuse the layout, which is loaded into memory when the app starts loading. The layout referenced by the viewstub tag will not be loaded, and will only be loaded when you need it at some point, saving CPU load time and memory when parsing layout.
Its meaning is to load the required layout files as needed, in actual development, there are a lot of layout files in the normal circumstances do not need to display, when the need for their display is displayed. For example, the layout of the network loading animation, this time there is no need to load the entire interface when it is initialized, through the viewstub can be used in the time of loading. Improved program performance.
Load Code on Demand:
((viewstub) Findviewbyid (R.id.stub_import)). Setvisibility (view.visible);
Or:
View Importpanel = ((viewstub) Findviewbyid (R.id.stub_import)). Inflate ();
Before I saw many friends on the Internet, said to set the view visibility to gone. The view is also not loaded into memory. In fact, this statement is wrong. From the Android source can be known, even if the view of the visiablity set to Gone,view will also be loaded in memory resources. That is, only viewstub loaded layout will not be loaded into memory resources until the app is launched.
③merge: Reduce the number of layout layers
1
The Merge tab is used to cancel the display of the layout hierarchy. As we all know, the root layout of Android top layout decorview is let framelayout. At this point in our layout, if we use the framelayout, it will cause the layout node to overlap the level overlay repeatedly draw. Android provides us with a call to hierarchy Viewer to view the layout node information. The tool is in the Sdk/tools directory.
Android Layout file optimization