android - Why <merge> root not call onFinishInflate() after inflation? -
my custom view not call onfinishinflate() after inflate(), found out custom view layout file root , android not call onfinishinflate() in condition. wonder why android way?
the comment onfinishinflate() following:
- finalize inflating view xml. called last phase * of inflation, after child views have been added.
if inflate layout file root tag , add view, can't receive onfinishinflate() callback. kind of strange me.
the following code snippet layoutinflater.java android 24.
void rinflate(xmlpullparser parser, view parent, context context, attributeset attrs, boolean finishinflate) throws xmlpullparserexception, ioexception { final int depth = parser.getdepth(); int type; while (((type = parser.next()) != xmlpullparser.end_tag || parser.getdepth() > depth) && type != xmlpullparser.end_document) { if (type != xmlpullparser.start_tag) { continue; } final string name = parser.getname(); if (tag_request_focus.equals(name)) { parserequestfocus(parser, parent); } else if (tag_tag.equals(name)) { parseviewtag(parser, parent, attrs); } else if (tag_include.equals(name)) { if (parser.getdepth() == 0) { throw new inflateexception("<include /> cannot root element"); } parseinclude(parser, context, parent, attrs); } else if (tag_merge.equals(name)) { throw new inflateexception("<merge /> must root element"); } else { final view view = createviewfromtag(parent, name, context, attrs); final viewgroup viewgroup = (viewgroup) parent; final viewgroup.layoutparams params = viewgroup.generatelayoutparams(attrs); rinflatechildren(parser, view, attrs, true); viewgroup.addview(view, params); } } if (finishinflate) { parent.onfinishinflate(); } }
Comments
Post a Comment