標籤:span linear parent lines ber post amp ati rip
merge結合include最佳化android布局,效果不知道。個人感覺使用上也有非常大的局限。只是還是瞭解一下。記錄下來。
布局檔案都要有根節點,但android中的布局嵌套過多會造成效能問題,於是在使用include嵌套的時候我們能夠使用merge作為根節點,這樣能夠降低布局嵌套,提高顯示速率。
<?xml version="1.0" encoding="utf-8"?><merge xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="張三" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="李四" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="王五" /></merge>
上面的介面在顯示的時候會自己主動嵌套到以下的檔案裡。
<LinearLayout 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" android:orientation="horizontal" tools:context="com.example.viewstub.MainActivity" > <include layout="@layout/top"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/toggle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" android:text="顯示/隱藏" /> <ViewStub android:id="@+id/vs" android:layout_margin="50dp" android:layout_width="match_parent" android:layout_height="match_parent" android:inflatedId="@+id/inflated_id" android:layout="@layout/view_stub_layout" /></LinearLayout>
我為什麼說這個局限性比較大呢?由於merge中的空間顯示的使用會採用主布局檔案的方式來顯示。比方我這裡主布局是linearlayout且是水平排列,那麼merge中的元素顯示出來之後也是水平排列,但是我假設想讓merge中的元素垂直排列呢?抱歉,做不到。
android開發之merge結合include最佳化布局