Loading Views On Demand

        有時候,我們的佈局中需要顯示一個很複雜的視圖,但這個視圖卻很少用到,這時我們便可使用ViewStub.

        ViewStub是一個沒有大小也不會被繪製的輕量級的視圖,它只會在需要要的時候纔會被繪製。


使用示例:

<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="bottom" />

((ViewStub) findViewById(R.id.stub_import)).setVisibility(View.VISIBLE);
// or
View importPanel = ((ViewStub) findViewById(R.id.stub_import)).inflate();

http://developer.android.com/intl/zh-cn/training/improving-layouts/loading-ondemand.html
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章