Read complete story

Android ViewStub using Data Binding

ViewStub:

A ViewStub is an invisible, zero-sized View that can be used to lazily inflate layout resources at runtime.

When a ViewStub is made visible, or when inflate() is invoked, the layout resource is inflated.

You can reduce memory usage and speed up rendering by loading the views only when they are needed.

Define ViewStub in XML file

 

Inflate ViewStub: 

We can specify layout at run time (viewStub!!.layoutResource) or in XML layout (android: layout)  attribute. A ViewStub can be load by using visible, or inflate().

 

. . .

Comment (1)

Add Your Comment

  • Vedesh Kumar
    I can inflate the views inside a LinearLayout and can get the same results. Why use this ViewStub?
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close