The <merge /> was created for the purpose of optimizing Android layouts by reducing the number of levels in view trees
You could not apply this trick if your layout was using a LinearLayout as its root tag for instance
<merge />can only be used as the root tag of an XML layout- When inflating a layout starting with a
<merge />, you must specify a parentViewGroupand you must setattachToRoottotrue(see the documentation of the inflate() method)
< merge xmlns:android = "http://schemas.android.com/apk/res/android" > < include layout = "@layout/okcancelbar_button" android:id = "@+id/okcancelbar_ok" /> < include layout = "@layout/okcancelbar_button" android:id = "@+id/okcancelbar_cancel" /> </ merge >
<merge>标签用于减少Android布局中视图树层级,从而优化布局性能。它不能作为LinearLayout的子元素使用,仅能作为XML布局文件的根标签。在使用时,需要指定父ViewGroup,并设置attachToRoot为true。

被折叠的 条评论
为什么被折叠?



