Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old September 10th, 2011, 07:03 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Sep 2011
Posts: 78
 
Device(s):
Carrier: Not Provided

Thanks: 2
Thanked 1 Time in 1 Post
Default UI Code vs XML

Hi, I'm new to android development and I was wondering how the more experienced users create their UIs. Do you prefer to write actual java code or use the xml method? The xml method seems easier but not as powerful. Are there advantages / disadvantages to one method over the other?

Thanks

The_app_main is offline  
Reply With Quote
sponsored links
Old September 10th, 2011, 07:52 AM   #2 (permalink)
Junior Member
 
Join Date: Jul 2011
Location: Moscow
Posts: 27
 
Device(s): HTC WildFire
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via ICQ to dimiter
Default

I use code method: usually i create an absolute layout and add views to it.
Advantages:
1)I can calculate all view sizes and coordinates depending screen parameters. So, i hav't support screen problems.
2)Usually XML UI design take a lot of time, code is faster.
3)Really, code design is more simple, IMHO.
dimiter is offline  
Reply With Quote
Old September 12th, 2011, 02:20 AM   #3 (permalink)
New Member
 
Join Date: Sep 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

has anybody got any experience of using xml editors to work with your xml files, are they any good for ui development?
anchinsha is offline  
Reply With Quote
Old September 23rd, 2011, 06:28 AM   #4 (permalink)
New Member
 
raduq's Avatar
 
Join Date: Sep 2011
Location: Cluj Napoca - Romania
Posts: 10
 
Device(s): Samsung Galaxy S2
Carrier: Not Provided

Thanks: 1
Thanked 1 Time in 1 Post
Default

Do you have an example where doing the UI only with code is faster than using XML?

I've made my UIs, until now, only with code and the XML seems like a breath of fresh air.

Maybe I'll get sick of using XML too and revert back to code for my UIs but I'll go with XML for now (just started developing Android apps, so I'm new to this field.. I've done desktop applications mostly).
raduq is offline  
Last edited by raduq; September 23rd, 2011 at 11:36 AM.
Reply With Quote
Old September 23rd, 2011, 11:29 AM   #5 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

Quote:
Originally Posted by dimiter View Post
I use code method: usually i create an absolute layout and add views to it.
Advantages:
1)I can calculate all view sizes and coordinates depending screen parameters. So, i hav't support screen problems.
2)Usually XML UI design take a lot of time, code is faster.
3)Really, code design is more simple, IMHO.

1) You can do this with XML too, and it is actually must easier (and more efficient) to do it in XML.
2) XML design is actually much faster than code design(both performance-wise and the amount of time taken to do it) if you know what you are doing.
3) This is just entirely untrue. Using hte XML cleans your code up a lot--you don't have all that UI stuff (which in large applications is a lot) in your code, ultimately making it much more readable.

I should also note that the use of XML is considered standard practice when it comes to Android development and, no matter what platform you are developing for, adhearing to standards is one of the things that seperates good code, from mediocre to bad code.
jonbonazza is offline  
Reply With Quote
Old September 24th, 2011, 08:56 AM   #6 (permalink)
Junior Member
 
Join Date: Jul 2011
Location: Moscow
Posts: 27
 
Device(s): HTC WildFire
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via ICQ to dimiter
Default

Look at this app: Engineer calculator - YouTube
How to develop you this with XML? Also it should look alike at all screens (all lines should be 9% of screen height, buttons should spend 100% screen width (in ANY screen)). Yes, it's possible, but it spend *2-3 more time, than code method. Is it efficient? With XML you have more files for different screens. In code method only one file contain IU for one activity: one interface - one file, it is logical, isn't it?
Quote:
you don't have all that UI stuff (which in large applications is a lot) in your code, ultimately making it much more readable.
You can accommodate IU design code in separate method, which can be minimized.

Quote:
I should also note that the use of XML is considered standard practice when it comes to Android development and, no matter what platform you are developing for, adhearing to standards is one of the things that seperates good code, from mediocre to bad code.
"Ad populum" argument. It is dogma. XML method SEEMS easier. Fresh developer made some siple apps with XML and it enjoy him. After some developr see, that his apps looks normal only in some screens. So he teach compatibility technologies in XML, because he habit to XML.

Also, code method more versatile: really, you are UI king. In XML you
depend screen configuration, orientation and different things.
dimiter is offline  
Last edited by dimiter; September 24th, 2011 at 09:13 AM.
Reply With Quote
Old September 24th, 2011, 09:03 AM   #7 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

You could easily make that design in XML. Anything you can do in code, you can also do in XML.

Quote:
Also, code method more versatile: really, you are UI king. In XML you
depend screen configuration, orientation and different things.
The whole point of the XML is to make it so you don't need to know the screen configurations. XML offers dp (device independant pixels), and you can create seperate folders, such as layout-land and layout-port, to specifiy the layouts for each orientation. When this is done, the android system automatically handles the swapping of the layouts when the orientation is changed.

You are arguing code is better than XML yet you obviously don't know how to use the XML how it was intended.
jonbonazza is offline  
Reply With Quote
Old September 24th, 2011, 09:31 AM   #8 (permalink)
Junior Member
 
Join Date: Jul 2011
Location: Moscow
Posts: 27
 
Device(s): HTC WildFire
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via ICQ to dimiter
Default

Quote:
You could easily make that design in XML. Anything you can do in code, you can also do in XML.
Arguments, please.

Quote:
The whole point of the XML is to make it so you don't need to know the screen configurations. XML offers dp (device independant pixels), and you can create seperate folders, such as layout-land and layout-port, to specifiy the layouts for each orientation. When this is done, the android system automatically handles the swapping of the layouts when the orientation is changed.
I know all it. Please, solve here equation for convert dp to screen size (width or height) procents: 1dp=x%. Find x. It should be universal (for any screens). It is inpossible. Only procent design can save you from problems with compatibility.
Are you disagree wit this ( http://androidforums.ru/dp-dip-v-android-t9197.html#entry64800 ) comments? It is russian forum, but it easy translte with Google.
Made a lot of folders -> a lot of files spend more time.
Also, with XML you (de-facto) cannot move you components in code.
dimiter is offline  
Last edited by dimiter; September 24th, 2011 at 10:10 AM.
Reply With Quote
Old September 26th, 2011, 10:15 AM   #9 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

Whoops double post. :x
jonbonazza is offline  
Last edited by jonbonazza; September 26th, 2011 at 10:17 AM.
Reply With Quote
Old September 26th, 2011, 10:16 AM   #10 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

Quote:
Originally Posted by dimiter View Post
Arguments, please.

I know all it. Please, solve here equation for convert dp to screen size (width or height) procents: 1dp=x%. Find x. It should be universal (for any screens). It is inpossible. Only procent design can save you from problems with compatibility.
Are you disagree wit this ( dp(dip) в Android - Android Forums - русское сообщество ОС Android. Форум по Android) comments? It is russian forum, but it easy translte with Google.
Made a lot of folders -> a lot of files spend more time.
Also, with XML you (de-facto) cannot move you components in code.
First of all, UI Design shouldn't be based on percentage of screen. If, for some reason you do need to do this, then it's not hard to use some trial and error. As for your equation, it depends on the base screen size that android uses for their dp units. Whatever they consider to be the base screen size, then on that size screen, 1dp = 1px. By then knowing the screen size you are on (in pixels), you can easily calculate percentages.

While there is some overhead of reading from an XML file, since XML is text-based it is so minimal, that it really doesn't make much of a difference. That's true for any platform.

That is not true. You can certainly move your components in code if you create the UI in XML.

I should also note that floating point operations are much less efficient than loading in a few XML files.
jonbonazza is offline  
Reply With Quote
sponsored links
Old September 27th, 2011, 08:08 AM   #11 (permalink)
Junior Member
 
Join Date: Jul 2011
Location: Moscow
Posts: 27
 
Device(s): HTC WildFire
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via ICQ to dimiter
Default

Quote:
1dp = 1px
Untrue, read russian forum stuff.

Quote:
First of all, UI Design shouldn't be based on percentage of screen. If, for some reason you do need to do this, then it's not hard to use some trial and error.
Some screens have nonstandard sizes. Do you make so many layouts?

Quote:
That is not true. You can certainly move your components in code if you create the UI in XML.
Really, you can move this components. But i mean de-facto it irrationally, because you should create LayoutParams objects and setParams. With code method you doing this is to create an interface.

Quote:
I should also note that floating point operations are much less efficient than loading in a few XML files.
This difference is so small that it can be neglected
dimiter is offline  
Reply With Quote
Old September 28th, 2011, 06:57 PM   #12 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

Quote:
Originally Posted by dimiter View Post
Untrue, read russian forum stuff.


Some screens have nonstandard sizes. Do you make so many layouts?


Really, you can move this components. But i mean de-facto it irrationally, because you should create LayoutParams objects and setParams. With code method you doing this is to create an interface.


This difference is so small that it can be neglected

1) You didn't read my whole paragraph on that. I know that 1dp != 1px in general.

2) You should make a version of your drawables for each hdpi, mdpi, and ldpi and include them in the appropriate folders. Layout XML files should be placed in either layout-land, or layout-port and then,when referencing a drawable, the android system will determine which one to use.

3) Due to poor English (I'm not insulting you, some people don't speak English natively, and I ma aware of this), I do not understand the third comment

4) Yes, this is true, but you were saying XML files had high overhead. While XML files do have overhead, float calculations are much less efficient, even though both are negligable.

I see that there is no swaying you from your decision to use programmatic UI development, but it should be noted that, unlike Java SE, Google intends Android UI to be done via XML, and standards exist to be adhered to. Although you might see your code has being better, when it goes against standards, it doesn't matter if it truly is better, it will be snared at by other developers.
jonbonazza is offline  
Reply With Quote
Old October 4th, 2011, 10:02 AM   #13 (permalink)
Junior Member
 
Join Date: Jul 2011
Location: Moscow
Posts: 27
 
Device(s): HTC WildFire
Carrier: Not Provided

Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via ICQ to dimiter
Default

Quote:
You didn't read my whole paragraph on that. I know that 1dp != 1px in general.
With XML you can't to develope percent design->can't to develope right design

Quote:
You should make a version of your drawables for each hdpi, mdpi, and ldpi and include them in the appropriate folders. Layout XML files should be placed in either layout-land, or layout-port and then,when referencing a drawable, the android system will determine which one to use.
No subject. I know all it. I am interesting, do you develope layouts for all screen sizes and densities? Usually design not need pictures.

Quote:
Yes, this is true, but you were saying XML files had high overhead. While XML files do have overhead, float calculations are much less efficient, even though both are negligable.
At first i mean it comment wrong. For subject: alldevelopers has different efficient of XML and code way. It depending:
1)Design type
2)Developer experience
If design is simple (approximately 5%) XML always more efficient. If design is complicated, fresh developer has significant advantage with code method. Else code wethod is little more efficient.


Quote:
It will be snared at by other developers
No. Code method is better, it use more expierence developers. For new coders XML very harmful: more developers undestrand object programming worse. Also fresh coders loss more apps because of poor UI (good XML design requires a long learning).
dimiter is offline  
Last edited by dimiter; October 4th, 2011 at 10:04 AM.
Reply With Quote
Old October 25th, 2012, 02:11 AM   #14 (permalink)
New Member
 
Join Date: Sep 2011
Posts: 3
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

take a look at liquid xml editor as well, ive been working with it for a few weeks now, its a much easier way of working with xml.
anchinsha is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:24 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.