Edd
Edd

Reputation: 658

Should I use Java or XML for Android layouts?

Is there a "best practice" or noticeable difference in performance between using Java to do layouts in Android over XML?

For the sake of it, assume we are just laying out a relatively simple UI which uses multiple activities.

Upvotes: 3

Views: 4844

Answers (3)

Ould Abba
Ould Abba

Reputation: 843

An advantage of XML layouts are better is that they permit to define multiple layouts with smaller code

for multi-language application u can define French and english UI and load the desired one at application startup

they permit to support many screen resolutions and orientation (define main.xml file for each profile)

also u can easily add and modify layout without touching u'r code

so, better to USE IT

Upvotes: 4

Mainguy
Mainguy

Reputation: 1669

I hate the term "best practice", but the tradeoffs would be nice to hear. From my perspective, xml layouts are good if you want android to handle the layouts automagically. This would be for things like data-entry type applications (like banking applications). Java layouts would be better for applications that need tight control of the UI (like angry birds)

Upvotes: 1

Reuben Scratton
Reuben Scratton

Reputation: 38727

Once you have a reasonable understanding of layout it's far, far easier and quicker to use XML.

Inflating layout XML is never going to be quite as fast as instantiating views manually, but the difference is likely to be very small (walking a binary XML tree is probably a cheap thing to do), and inflating should be way too infrequent an event to think about optimizing for.

Upvotes: 5

Related Questions