Merge with include to optimize the Android layout, the effect is not known, the personal feeling there is also a lot of limitations, but still understand, recorded.
Layout files have root nodes, but too many nesting of layouts in Android can cause performance problems, so when using include nesting we use merge as the root node, which reduces layout nesting and increases the display rate.
<?xml version= "1.0" encoding= "Utf-8"?><merge xmlns:android="Http://schemas.android.com/apk/res/android" > <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="Zhang San" /> <TextViewandroid:layout_width="Wrap_content"android:layout_height= "Wrap_content" Android:text="John Doe" /> <TextViewandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:text="Harry" /> </Merge>
The above interface is automatically nested into the following file when it is displayed.
<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 =/> <viewstubandroid: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>
Why do I say this limitation is relatively large? Because the use of the space display in the merge is displayed in the form of the main layout file, such as my main layout is linearlayout and horizontally arranged, then the elements in the merge are displayed horizontally, but if I want to arrange the elements in the merge vertically? Sorry, I can't do that.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. If there is a wrong place, I would appreciate it if I could criticize it.
Android development merge with include optimized layout