On demand loading view for Android layout performance optimization
Sometimes applications have complex layouts that are rarely used. Reloading them when needed can reduce memory consumption and speed up the rendering of the interface.
Define viewstub
Viewstub is a lightweight view that has no height, width, and doesn't draw anything. Therefore, the cost of loading and unloading is very low. Each viewstub can use the Android: layout property to specify the layout to load.
The following viewstub is used to load a translucent ProgressBar. It only appears when a new job starts.
Load viewstub
When you need to load the layout specified by viewstub, you can use the setvisibility (view. Visible) method or the inflate () method, which have the same effect.
Note: the inflate () method will return a view after loading. Therefore, you do not need to use findviewbyid () to find the root view of this layout. Once the view hosted by the viewstub is loaded, the viewstub will no longer be part of the view hierarchy. It will be replaced by the loaded layout, and the ID of the layout will be changed to the ID specified by the Android: expandid property of viewstub.
Note: the disadvantage of viewstub is that it currently does not support the < merge / > label of the root view to load the layout.
The above is the on-demand loading view of Android layout performance optimization introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!