I’ve read Romain Guy’s post on the <merge /> tag, but I still don’t understand how it’s useful. Is it a sort-of replacement of the <Frame /> tag, or is it used like so:
<merge xmlns:android="....">
<LinearLayout ...>
.
.
.
</LinearLayout>
</merge>
then <include /> the code in another file?
<merge/>is useful because it can get rid of unneeded ViewGroups, i.e. layouts that are simply used to wrap other views and serve no purpose themselves.For example, if you were to
<include/>a layout from another file without using merge, the two files might look something like this:layout1.xml:
layout2.xml:
which is functionally equivalent to this single layout:
That FrameLayout in layout2.xml may not be useful.
<merge/>helps get rid of it. Here’s what it looks like using merge (layout1.xml doesn’t change):layout2.xml:
This is functionally equivalent to this layout:
but since you are using
<include/>you can reuse the layout elsewhere. It doesn’t have to be used to replace only FrameLayouts – you can use it to replace any layout that isn’t adding something useful to the way your view looks/behaves.