今天使用了merge来修饰我的布局文件的根节点,原想是为了减少布局层次。
结果在使用inflate加载此布局的时候出现了错误:
inflater.inflate(R.layout.toast_submit2, null);
android.view.InflateException: <merge /> can be used only with a valid ViewGroup root and attachToRoot=true
要为merge指定一个父控件,并且把它关联到父控件上。
所以在没有父布局的情况下需要加载的话,就不能使用merge标签来修饰布局文件了。
附上 merge的使用注意事项: