/** * Obtains the LayoutInflater from the given context. */ publicstatic LayoutInflater from(Context context) { LayoutInflaterLayoutInflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (LayoutInflater == null) { thrownewAssertionError("LayoutInflater not found."); } return LayoutInflater; }
try { // Look for the root node. int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty }
if (type != XmlPullParser.START_TAG) { thrownewInflateException(parser.getPositionDescription() + ": No start tag found!"); }
if (TAG_MERGE.equals(name)) { if (root == null || !attachToRoot) { thrownewInflateException("<merge /> can be used only with a valid " + "ViewGroup root and attachToRoot=true"); }
rInflate(parser, root, inflaterContext, attrs, false); } else { // Temp is the root view that was found in the xml finalViewtemp= createViewFromTag(root, name, inflaterContext, attrs);
ViewGroup.LayoutParamsparams=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); } }
if (DEBUG) { System.out.println("-----> start inflating children"); }
// Inflate all children under temp against its context. rInflateChildren(parser, temp, attrs, true);
if (DEBUG) { System.out.println("-----> done inflating children"); }
// 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; } }