Android Guides | Samples

Android.Views.ViewStub Class

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

See Also: ViewStub

Syntax

[Android.Runtime.Register("android/view/ViewStub", DoNotGenerateAcw=true)]
public sealed class ViewStub : View

Remarks

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 ViewStub.Inflate is invoked, the layout resource is inflated. The ViewStub then replaces itself in its parent with the inflated View or Views. Therefore, the ViewStub exists in the view hierarchy until ViewStub.setVisibility(int) or ViewStub.Inflate is invoked. The inflated View is added to the ViewStub's parent with the ViewStub's layout parameters. Similarly, you can define/override the inflate View's id by using the ViewStub's inflatedId property. For instance:

xml Example

     <ViewStub android:id="@+id/stub"
               android:inflatedId="@+id/subTree"
               android:layout="@layout/mySubTree"
               android:layout_width="120dip"
               android:layout_height="40dip" />
The ViewStub thus defined can be found using the id "stub." After inflation of the layout resource "mySubTree," the ViewStub is removed from its parent. The View created by inflating the layout resource "mySubTree" can be found using the id "subTree," specified by the inflatedId property. The inflated View is finally assigned a width of 120dip and a height of 40dip. The preferred way to perform the inflation of the layout resource is the following:

java Example

     ViewStub stub = (ViewStub) findViewById(R.id.stub);
     View inflated = stub.inflate();
When ViewStub.Inflate is invoked, the ViewStub is replaced by the inflated View and the inflated View is returned. This lets applications get a reference to the inflated View without executing an extra findViewById().

[Android Documentation]

Requirements

Namespace: Android.Views
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Views.ViewStub are listed below.

See Also: View

Public Constructors

Public Properties

InflatedIdInt32. Returns the id taken by the inflated view.
LayoutInflaterLayoutInflater. Get current LayoutInflater used in ViewStub.Inflate.
LayoutResourceInt32. Returns the layout resource that will be used by ViewStub.setVisibility(int) or ViewStub.Inflate to replace this StubbedView in its parent by another view.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Inflate() : View
Inflates the layout resource identified by ViewStub.LayoutResource and replaces this StubbedView in its parent by the inflated layout resource.
SetOnInflateListener(ViewStub+IOnInflateListener)
Specifies the inflate listener to be notified after this ViewStub successfully inflated its layout resource.

Public Events