I am far from an expert when it comes to understanding the minutia of code compilation. But I am learning some android development, and I noticed how layouts and other things are essentially parsed out of xml. I was wondering if this parsing happens at compile time or at runtime? If it is at runtime, it seems like there might be some overhead associated with parsing out a very complex layout.
Hope that this question isn't 开发者_运维问答too vague or doesn't make sense.
The parsing of the XML to create the layout happens at compile time. You will notice that if anything in your XML is malformed, the compiler will throw an error.
Certain aspects of the layout such as calculating relative position happen at run time, but there is nothing that can be done to avoid that.
Parsing happens both at Runtime and Compile time for different purposes. First, at compile time it is usually layouts and drawables that are parsed for rendering by the layout editor and for adding ID references for code. Styles, themes, and attributes also get compiled at this step allowing for some very powerful XML resource bundling.
Runtime parsing happens for every resource, on the fly and as its needed. This is accomplished through several inflater classes, and other supporting classes.
精彩评论