// Temp is the root view that was found in the xml final View temp = createViewFromTag(root, name, attrs, false); ViewGroup.LayoutParams params = null; if (root != null) { if (DEBUG) { System.out.println("Creating params from root: " + root); } // Create layout params that match root, if supplied params = root.generateLayoutParams(attrs); if (!attachToRoot) { // Set the layout params for temp if we are not // attaching. (If we are, we use addView, below) temp.setLayoutParams(params); } // We are supposed to attach all the views we found (int temp) // to root. Do that now. if (root != null && attachToRoot) { root.addView(temp, params); } // Decide whether to return the root that was passed in or the // top view found in xml. if (root == null || !attachToRoot) { result = temp; } ... return result;
this is the LayoutInflater code, as you can see, if you added root , then it is not null, generated layoutParams from root.
and then if the thrid parameter is false , there is only make temp.setLayoutParams(params) , which params generated by root! and pace as a return ....
if attachToRoot true , root will execute root.addView (temp, params), and then the root is returned.
if you just do LayoutInflater.from(this).inflate(R.layout.popup_choose_type, null); , and if you set some attribute as paddingBottom , it will surprise you that this will not work !! due to the loss of LayoutParams !
How to decide, you can see here
source share