In android, we can design user interfaces by two methods: Procedural and declarative. In procedural we write code in the program to design interfaces as we do in swings. While in declarative design we do in the XML files under res folder. For example, creating button inside res–>layout–>main.xml using <Button> tag. The declarative design is more preferred method among the two.
So, my question is that why to prefer designing by declaration. How much efficient is designing the interfaces through XML’s.
According to the documentation the advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile. For example, you can create XML layouts for different screen orientations, different device screen sizes, and different languages. Additionally, declaring the layout in XML makes it easier to visualize the structure of your UI, so it’s easier to debug problems. You can go through this for more.