Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I would like to know why we use XML for the creating user interface layouts in Android. I know that it decouples the business logic from the design but what is the significance of the XML other than that?

Also I would like to know the significance of the auto-generated R.java file in this. All I know that it is generated according to the changes in the resources and that it helps us to access the widgets and resources through their IDs.

It would be great if someone could give a clear idea on these two aspects.

like image 257
rogerstone Avatar asked Apr 13 '11 06:04

rogerstone


People also ask

Why is XML used for designing in Android UI explain?

Xml as itself is well readable both by human and machine. Also, it is scalable and simple to develop. In Android we use XML for designing our layouts because XML is lightweight language so it doesn't make our layout heavy.

Why do we use XML file in Android?

XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.

Why layout are created using XML file?

Using Android's XML vocabulary, you can quickly design UI layouts and the screen elements they contain, in the same way you create web pages in HTML — with a series of nested elements. Each layout file must contain exactly one root element, which must be a View or ViewGroup object.

Why XML is used in Android instead of HTML?

I think the xml is chosen because the xml tags are defined in android according to the UI framework classes and the attributes are defined corresponding to the member variables of the class in the UI framework. This mapping was not possible for the html.


1 Answers

Unlike what everyone said about the xml being easy and efficient.Here is what i read from Hello Android from Ed Brunnette 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.

like image 106
rogerstone Avatar answered Jun 24 '23 13:06

rogerstone