tags:

views:

49

answers:

1

I am new to Android.

I wish to know how to design a screen by using java in Android.

Design via xml and design via java which one is the best?

+1  A: 

Design via xml is easier to maintain. For example, if you have to change something in your UI you just change it in one xml file instead of looking for it in all your source code.

On the other side, in java you can do some staff more quickly. Let's say you need to display a matrix of button. In java you can create and display them with a loop instead of creating them via xml.

To sum up, it depends on what you have to do. If you need to design more or less static UIs, opt for xml and use Java only to edit them at runtime.

klez
Thanks for your Reply.I have to design the screen by using java.Can you give some basic ideas about it?
RMRK
You should be more precise about what you need to accomplish, because you're not giving that much infos. Have you given a shot at Android documentation?
klez
Since you are new to Android I would find that hard for you. Try first the XML and see some tutorials. When you think how your layout would be in XML think like it was a HTML file and relative nested display.
Pentium10
I just add the image button.At the time of onfocus i wish to change the image button's background(using java).
RMRK
Take a look at the `setBackground()` method of the `Button` class
klez
You can use a StateListDrawable defined in XML to do things like that for you rather than change the background manually in code. These XML files go in your res/drawable directory and can be referenced using R.drawable.foo just like any other Drawable resource. Here's an example of a background drawable for buttons from the Android framework itself: http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/res/res/drawable/btn_default.xml;h=476508464e2d1ac87e6b6e417c829584d3e998b1;hb=HEAD
adamp