Why is XML used for the creation of UI layouts in Android?

XML is easy to parse and manipulate programmatically, it's basically a tree structure and most UI creation tools already use it. It really has nothing to do with decoupling business logic because you can define Java code in Android using a Model-View-Controller pattern just as well.

The auto-generated R.java file is a helper for the IDE so that you can get the benefit of autocomplete when you want to access a resource. It also stops you from making stupid mistakes since the compiler will complain if you try to access a resource you haven't defined. If you were using a simple properties file you wouldn't know until runtime that the 'key' you are using is missing.


Unlike what everyone said about the XML being easy and efficient. Here is what I read in Hello Android by Ed Brunnette (p. 49) which made sense.

Android is optimized for mobile devices with limited memory and horsepower, so you may find it strange that it uses XML so pervasively. After all, XML is a verbose, human-readable format not known for its brevity or efficiency, right?

Although you see XML when writing your program, the Eclipse plug-in invokes the Android resource compiler, aapt, to preprocess the XML into a compressed binary format.**It is this format, not the original XML text, that is stored on the device.

This was the kind of answer that i was looking for.(sorry if my question meant otherwise).

The reason that XML was chosen is mainly because of its familiarity and the number of IDE tools that natively support it. The developers could have chosen JSON for example and still compiled that to binary.The auto-generated R.java file is a helper for the IDE so that you can get the benefit of autocomplete when you want to access a resource.


Same as why is silverlight with xml the answer is simple xml give power by integration and scalability. R.java is for indexing having things organized is never bad. Sorry my english


One possible reason is that you need not have any working java underneath in order to be able to see the visual layout of the interface you are working on. The xml ui element/page is essentially a document that you can parse and display. If this were a source file you would have to either carefully parse it or compile and run it (all of which are more complex than parsing xml)

Tags:

Java

Android