Pilpel Pilpel - 2 months ago 18
Android Question

Creating layouts without an XML

I've read that layout XML files are interpreted to Java code, building a View hierarchy this way.

First, how and where is this done? Can someone link me to the place that does this interpretation?

Second, is it possible to create a complete layout without using XML files? If the answer is yes, is it useful in any way? (does it have advantages over XML files) Do big apps do this?

Answer

I've read that layout XML files are interpreted to Java code, building a View hierarchy this way.

Not by most definitions of the phrase "interpreted to Java code". The XML is parsed and used to create Java objects corresponding to the views expressed in the XML.

Can someone link me to the place that does this interpretation?

You are looking for LayoutInflater, presumably.

is it possible to create a complete layout without using XML files?

Sure.

is it useful in any way?

For trivial UIs (e.g., the whole content view is a WebView), it's a bit simpler and a tiny bit faster.

Note that many games will skip Java-based UIs entirely, rendering their output from C/C++ using OpenGL. Similarly, hybrid app frameworks (e.g., PhoneGap) will skip most of the Java-based UI work, as they render their UIs via Web technologies (HTML, CSS, JS, etc.).