Viewstub is a control for loading layout files that controls the display of that part in the view, functions like the Android:visibility property, and you can use View.gone to control the hiding and display of a view control.
Of course, there are some differences between viewstub and Android:visibility attributes, and there are certain advantages. Viewstub when the software is started, the software loads only the views of the Viewstub section without loading the corresponding view associated with the viewstub , and the view associated with viewstub is loaded after the inflate is called. This can reduce the memory consumption of the phone, While the use of View.gone can be implemented to hide and display the view control, but you need to set up all the controls in the layout file, although you can set the property to View.gone, but when loading the corresponding view, you still need to load the corresponding views control all, the memory consumption is too large, so viewstub Can play a certain role, to properly use the combination of the two.
However, Viewstub has a certain flaw, it can only load a view control, after loading the view control, you cannot use viewstub and then set the associated View control.
Example code:
<viewstub
Android:id= "@+id/vs"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_marginleft="5dip"
android:layout_marginright="5dip"
android:layout_margintop="10dip"
android:layout= "@layout/popupwindow"/>
Where the Android:layout property is its associated layout
In the code is Findviewbyid (R.id.vs). Inflate ();
You can display the associated layout as an alternative to viewstub, while some of the corresponding properties in the viewstub settings are also passed to the associated layout.
Like android:layout_marginleft="5dip"
android:layout_marginright="5dip"
android:layout_margintop="10dip"
will be passed to the control in @layout/popupwindow
Android Development-viewstub Use