title: Android Data Binding - how to use ViewStub with data binding
body: <p>Is there anyway to use viewStubs with dataBinding ? can ViewStubProxy help ?</p>
  
  <p>My stub current looks like this:</p>
  
  <pre><code>    &lt;ViewStub
    android:id="@+id/stub_import"
    android:inflatedId="@+id/panel_import"
  
    android:layout="@layout/progress_overlay"
  
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="@{myobject.bottom ? bottom:top}" /&gt;
  </code></pre>
  
  <p>But this layout will be replaced when i inflate the viewStub so how can ViewStubs be used with android dataBinding ?</p>
  
  <p>this is what i see from the <a href="http://developer.android.com/tools/data-binding/guide.html#data_binding_layout_files" rel="noreferrer">docs</a>:</p>
  
  <blockquote>
    <blockquote>
      <p>ViewStubs</p>
    </blockquote>
    
    <p>ViewStubs are a little different from normal Views. They start off
    invisible and when they either are made visible or are explicitly told
    to inflate, they replace themselves in the layout by inflating another
    layout.</p>
    
    <p>Because the ViewStub essentially disappears from the View hierarchy,
    the View in the binding object must also disappear to allow
    collection. Because the Views are final, a ViewStubProxy object takes
    the place of the ViewStub, giving the developer access to the ViewStub
    when it exists and also access to the inflated View hierarchy when the
    ViewStub has been inflated.</p>
    
    <p>When inflating another layout, a binding must be established for the
    new layout. Therefore, the ViewStubProxy must listen to the ViewStub's
    ViewStub.OnInflateListener and establish the binding at that time.
    Since only one can exist, the ViewStubProxy allows the developer to
    set an OnInflateListener on it that it will call after establishing
    the binding.</p>
  </blockquote>