基本思想就是懒加载,
<ViewStub android:id="@+id/stub"
android:inflatedId="@+id/subTree"
android:layout="@layout/mySubTree"
android:layout_width="120dip"
android:layout_height=“40dip”/>
ViewStub stub = (ViewStub) findViewById(R.id.stub);
View inflated = stub.inflate();
思路是:1.不需要显示mySubTree时,ViewStub占位置,放入parent中;
2.当需要显示mySubTree时,用View替换parent中的ViewStub。