UseViewStubLazy Loading 1.ViewStubLazy Loading
Viewstub is an invisible, size 0 view, the best use is to implement the view delay loading, when needed to load the view, can be common in Java Performance optimization method lazy loading.
When the setvisibility function that calls Viewstub is set to visible or the call inflate initializes the view, the resource referenced by the viewstub begins to initialize, and then references the resource substitution viewstub its own location to populate the Viewstub location. Therefore, before calling the setvisibility (int) or inflate () function, a viewstub exists in the component tree hierarchy, but because Viewstub is very lightweight, this has a very small impact on performance. You can redefine the referenced layout ID by viewstub the Inflatedid property. For example:
<viewstub android:id= "@+id/stub" android:layout_width= "Match_parent" Android:layout_height= "Match_parent" android:inflatedid= "@+id/subtree" android: Layout= "@layout/activity_viewstub_item"/>
// get to Viewstub Final Viewstub stub = (Viewstub) Findviewbyid (r.id.stub); // test fill layout with inflate () New Handler () { @Override publicvoid handlemessage (Message msg) { = stub.inflate (); }}; Handler.sendemptymessagedelayed (1, 7000);
I've been here a while to call the stub.inflate(); method, load the layout, and we don't have to go to Findviewbyid to load the view anymore.
Android optimized--ui optimization (iii)