1、Merge
作用:直接将其中的子元素添加到Merge标签的Parent中,避免引入额外的层级。
使用时的要求:
(1)Merge只能用在布局XMl文件的根元素;
(2)使用Merge来加载一个布局时,必须指定一个ViewGroup作为其父元素,并且要设置加载的attachToRoot参数为true(参照inflate(int,ViewGroup,boolean));
(3)不能在ViewStub中使用,因为ViewStub的inflate方法中根本没有attachToRoot的设置。
具体使用:
先定义需要的布局文件(test_merge.xml):
<merge
xmlns:android="http://schemas.android.