Use a ViewStub
instead of include
:
<ViewStub
android:id="@+id/layout_stub"
android:inflatedId="@+id/message_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.75" />
Then in code, get a reference to the stub, set its layout resource, and inflate it:
ViewStub stub = (ViewStub) findViewById(R.id.layout_stub);
stub.setLayoutResource(R.layout.whatever_layout_you_want);
View inflated = stub.inflate();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…