Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <include> and <ViewStub> in android

Tags:

What are the differences between <\include> tag and <\ViewStub> tag and which one is preferrable while designing the layout.

Thanks,
venu

like image 861
Venugopal Avatar asked Jul 04 '11 04:07

Venugopal


1 Answers

The < include /> will just include the xml contents in your base xml file as if the whole thing was just a single big file. It's a nice way to share layout parts between different layouts.

The < ViewStub /> is a bit different because it is not directly included, and will be loaded only when you actually use it/need it, ie, when you set its visibility to VISIBLE (actually visible) or INVISIBLE (still not visible, but its size isn't 0 anymore). This a nice optimization because you could have a complex layout with tons of small views or headers anywhere, and still have your Activity load up really fast. Once you use one of those views, it'll be loaded.

like image 119
Gregory Avatar answered Sep 20 '22 20:09

Gregory