Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
125 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...