merge combined with include to optimize Android layout, I don’t know the effect, I personally feel that there are great limitations in use, but I will understand it and record it.
Layout files must have root nodes, but too much layout nesting in Android will cause performance problems. Therefore, when using include nesting, we can use merge as the root node, which can reduce layout nesting and improve the display rate.
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:andro > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Zhang San" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Li Si" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Wang Wu" /> </merge>
The above interface will be automatically nested into the following file when displayed.
<LinearLayout xmlns:andro xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context="" > <include layout="@layout/top"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" android:text="Show/Hide" /> <ViewStub android: 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 that this is more limited? Because the use of space display in merge will be displayed in the form of a main layout file, for example, the main layout here is linearlayout and arranged horizontally, then the elements in merge are also arranged horizontally after they are displayed, but what if I want the elements in merge to be arranged vertically? Sorry, I can't do it.
Original link:/u012702547/article/details/47133647
The above is all about this article, I hope it will be helpful for everyone to learn Android software programming.