情况一: root =null, attachToRoot = false;
View temp = createViewFromTag(root, name, attrs);
// Inflate all children under temp
rInflate(parser, temp, attrs, true);
return temp;
情况二:root != null, attachToRoot = false;
View temp = createViewFromTag(root, name, attrs);
ViewGroup.LayoutParams params = root.generateLayoutParams(attrs);
temp.setLayoutParams(params);
// Inflate all children under temp
rInflate(parser, temp, attrs, true);
return temp;
情况三:root != null, attachToRoot = true;
View temp = createViewFromTag(root, name, attrs);
ViewGroup.LayoutParams params = root.generateLayoutParams(attrs);
temp.setLayoutParams(params);
// Inflate all children under temp
rInflate(parser, temp, attrs, true);
root.addView(temp, params);
return root;
总结:
root为空时, 返回temp。
root 不为空时, attachToRoot = true 。 返回root;
attachToRoot = false。设置temp layoutParams 。返回temp。