XML can completely separate the content and structure of the program, can realize the thorough separation of content management and process management, reduce the development coupling degree, and make the project management easier. and XML has a unified standard syntax, any system and product support XML documents, all have a unified format and syntax, for cross-platform migration, extensibility. With a pattern like swing, the coupling is high and the cost of maintaining XML is higher thanXML is a common international standard (if you can create such standards), and now almost all of the computer language will be used in XML, will deal with him, use can do interface and code separation (reduce coupling and portability); Swing is just part of Java class Library, If you use swing then you might as well use Java directly.
The best thing about Android layout is to write in the Res/layout folder in XML, so that you can not only separate the foreground interface from the business logic, but also make the code clearer.
More importantly, it is easy to adapt the model and app internationalization.
Placing these controls in an XML file is an important aspect of Android to ensure an MVC architecture, where layout is the view layer, isolated from the logic code,
So surely it's better to put it in an XML file? However, there is no way for dynamic controls to be put into Java code!
Why Android uses XML to describe the interface