以下內(nèi)容整理自互聯(lián)網(wǎng),僅用于個人學(xué)習(xí)
1. Merge
Merge作為A布局根標(biāo)簽,其他布局文件B通過include引用A時,Merge標(biāo)簽會被去掉,在include里存放的是merge的子標(biāo)簽,以此減少布局文件的層次。
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="merge標(biāo)簽使用" />
</merge>
如上面的布局,外層的merge會在最終的布局中去掉。
2. ViewStub
一個寬高都為0的view,默認(rèn)不可見,只有通過調(diào)用setVisibility設(shè)置為可見或者調(diào)用了ViewStub.inflate()時,ViewStub所指向的布局文件才會被inflate和實例化,然后ViewStub布局屬性全部傳給它所指向的布局。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal">
<ViewStub
android:id="@+id/viewstub_demo_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:layout="@layout/viewstub_demo_text_layout"/>
</LinearLayout>
在onCreate方法中
ViewStub stub = (ViewStub) findViewById(R.id.viewstub_demo_text);
stub.inflate();