Use <merge/> tag
This <merge/> tag helps us eliminate redundant view Groups when including a layout, for example, your main layout file is a vertical linearlayout.
<linearyout xmlns:android = http://schemas.android.com/apk/res/android
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation = "vertical" >
<button
Android:layout_width="Fill_parent"
Android:layout_height="Wrap_content"
Android:text="Text"/>
<button
Android:layout_width="Fill_parent"
Android:layout_height="Wrap_content"
Android:text="Text"/>
<include layout= "@layout/ok_no_pannel" />
</linearyout>
at this point: analyze the following Ok_no_pannel.xml , the wording of the document:
<linearyout xmlns:android = http://schemas.android.com/apk/res/android
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation = "vertical" >
<button android:layout_width = "Fill_parent" android:layout_height = "Wrap_content" android:text = "@string/add"/> <button android:layout_width = "Fill_parent" android:layout_height = "Wrap_content" android:text = "@string/delete"/> </linearyout >
The wording of the above documents, you will find that once include execution is done and you will find that there is a layer of LinearLayout It's useless to pass Merge label, we can easily solve this problem.
<merge xmlns:android="http://schemas.android.com/apk/res/android "> <button android:layout_width = "Fill_parent" android:layout_height = "Wrap_content" android:text = "@string/add"/> <button android:layout_width = "Fill_parent" android:layout_height = "Wrap_content" android:text = "@string/delete"/> </merge>
Now , when you pass include tag to embed a layout file in another layout file, the system ignores Merge label, directly add two Button element is placed in the layout file instead of the include the location of the label.
The author has a saying: if you need Android Chinese API, please sweep the following QR code, your concern, is my motivation.
Android Chinese api-<merge/> tags