Problem: How to implement ViewStub in Android?
Description:
I have used ViewStub almost for implementing Title Bar (i.e. Header) for most of the application. I have defined a Title bar layout only for once and then I have re-used the same layout for every activity by the use of ViewStub.
Now, let me clear idea for “What is ViewStub” actually?
A ViewStub is a dumb and lightweight view. It has no dimension, it does not draw anything and does not participate in the layout in any way. This means a ViewStub is very cheap to inflate and very cheap to keep in a view hierarchy. A ViewStub can be best described as a lazy include. The layout referenced by a ViewStub is inflated and added to the user interface only when you decide so.
I am sure you have also came across this article: Layout Tricks: Using ViewStubs
Output of this example code:
Download Full example code here: Android ViewStub example