Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 832
Edd Avatar asked Dec 06 '25 02:12

Edd


2 Answers

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.

like image 178
Reuben Scratton Avatar answered Dec 07 '25 17:12

Reuben Scratton


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

like image 44
Ould Abba Avatar answered Dec 07 '25 17:12

Ould Abba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!