Is Zen Coding/Emmet available for Android? - android

Zen Coding/Emmet seems to be perfect to build those tedious Android XML layouts. Is it available for Android in any way or on any text editors? If not, would it be possible to start coding it for one?

Emmet is not tied to HTML and CSS. For XML syntax, it takes any expression and converts it to XML code so basically it supports Android XML layouts out-of-box. You can also add your own element aliases to increase productivity: http://docs.emmet.io/customization/snippets/

Related

Any way to avoid "android:" statements in Android XML layout file?

Is there any way to avoid hundreds of "android:" statements in an Android XML layout file? I am new to Android and I find the "android:" statements make layouts very hard to read. Plus they are a pain to constantly type.
For example, instead of this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
I would like to just see this:
layout_width="wrap_content"
layout_height="wrap_content"
layout_column="2"
If you're using Eclipse (and presumably Android Studio has similar functionality, but I've not used it) you can auto complete layout properties, e.g. if you type w then ctrl + space it will auto complete this to android:layout_width in most instances. You never really need to type the android: part.
I'm not aware of a way to remove the namespaces.
No. That is needed to know it is part of the Android framework. Instead of say a custom style or custom View. I've done a little bit of Android coding and it really isn't a big deal.
For example, there is a copy/paste feature which can make it go faster. Also, most IDEs have autocomplete which is very handy.

Using XML in Android for development

Hi,
How to use XML code instead of Android code to be used regarding UI development? In what manner XML is different from ordinary Android code?
Basically, if you've static elements in your layout, it's better to use XML. If your layout has a property to change itself dynamically, then it's better to go for Java. When it comes to usefulness as such, using XML is a bit better because you can easily re-configure your XML when compared to the dynamically running code. Finally, designing is a matter of choice and opinion.
Its much easier to develop UI using XML than by JAVA code mainly due to visual Drag-and-Drop feature. But by XML way of laying out views is Static in Nature but by Java code it can made to work during Runtime(may be adjusted to different conditions). So it is recommended that part of the layout which you think, undergoes no change in time should be implemented by XML and vice-versa by JAVA coding. Also static UI by XML can be overrided by JAVA cod during runtime as per requirment.
Read this ,you will get your answer :
http://developer.android.com/guide/topics/ui/declaring-layout.html

How do I get about adding something to my Android Layout?

I am a complete newb to Android and have seen tutorials that show widgets being added via XML and also via Java. I want to know what industry experts prefer and why. The author/narrator seems to prefer XML saying it gives more control but I wanted to get feedback from veterans.
With XML Tutorial
Without XML Tutorial
Thank You and again I apologize for a complete newb question.
XML layouts are very easy compared to java code. The coding also very less than java.
You can prefer any of these two, but all authors prefer XML because its easy.
Please read information available at this link, you will get an idea.
XML Layouts
Declare UI elements in XML (most
common and preferred)
Android provides a straightforward XML vocabulary
that corresponds to the View classes and subclasses,
such as those for UI controls called widgets
(TextView, Button, etc.) and layouts.
Instantiate layout elements at
runtime (programmatically in Java code)
Your application can create View and ViewGroup
objects (and manipulate their properties)
programmatically (in Java code).
Advantages of : Declaring UI in XML
• Separation of the presentation from the code
that controls its behavior
You can modify UI without having to modify your
source code and recompile
For example, you can create XML layouts for
different screen orientations, different device screen
sizes, and different languages
• Easier to visualize the structure of your UI
(without writing any code)
Easier to design/debug UI
Visualizer tool (like the one in Eclipse IDE)
Advantages of : Instantiate layout elements at runtime
• While showing dynamic data
When your application need to show dynamically some information for example loading title from web then you need as many text-view per title and you are not sure at design time about this at that time this can be preffered
You can make your application design both ways and both will help you the same,It will depened on your requirement whether you require to create it at runtime or not,Anyways I think while you can make separate XML file why need to do it in your Activity java file and get more complexity in code unnecessarily.
XML layout method is very easy, fast and easy to visualize. You can do a paper-pencil work first and simply do it in XML.
XML layouts are easy to manage - you can change the caption, position, look & feel, size, colors etc. in the XML layout, without altering a single line of the Java Code. The App will generate the Java Code for the layout from your XML file.
XML layout does not compell that you should write the whole XML codes. Instead, you can use a GUI editor and you arrange the controls on screen, and it will generate the XML for you. There are lots of GUI design tools. Eg.: http://www.droiddraw.org
Now, you can go for Java Code UI layout only if you cannot determine the layout at the time of writing the App. Say, you are designing an Android App for Web Designers - An app to create HTML Forms and create the HTML code (a simple HTML editor tool), then you are unable to know which type of layout the user is going to do. At this point, the better option is choosing Dynamic Layout (or Java Code layout)
Almost every Android programmer chooses to do layout in XML. That's the beast and easiest way to do it.

Deserialize Android Layout XML?

Whats the best way for me to take an android XML layout file and automatically generate the equivalent Java code? Does a tool like JAXB work and if so how do I use it?
It's an interesting idea, though a bit useless IMHO. Why would one want to do it? Inflating an XML is very fast operation and hides a lot of complexity - for example it takes into account what is the current DisplayMetrics and recalculates layout parameters (width/height) appropriately to the density and size of the screen... It's also very fast because it does not actually require XML parsing - parsing is done at compilation time and what is actually stored by android is a binary version of the layout which is optimized for efficiency (that's why you cannot build layout XML dynamically from an XML file).
If you would like to modify the Java code and add/remove some elements then it is much more efficient to inflate the XML and then do all the modifications -less clutter simpler code and all the calculations are done for you...
Whats the best way for me to take an android XML layout file and automatically generate the equivalent Java code?
Step #1: Parse the XML.
Step #2: Generate the Java code. You'll have to pray that you can build your own AttributeSet implementation that works with your generated code, otherwise this will be a very complex problem.
Does a tool like JAXB work
AFAIK, JAXB needs an XML Schema, and there is no such schema possible for the Android layout file.
Whatever problem you're trying to solve this way, there's probably a better solution.
I just want a simple way to take an android xml layout and pass it to, say, a command line tool to generate the equivalent Java.
I seriously doubt that this will be "simple" for any reasonable definition of the term.

Which is best, Java or Xml for developing android apps

I have know core java, I want to develop android apps, in few sites I saw apps in XML in few Java.Which is best and easy to use Java or XML?
I'm assuming you are talking about the UI, not the complete app:
For everything statically I use XML, because it is easy to find in the structure of your project.
Some parts you want to create dynamically and you have no other choice then to use Code. Be smart, in this, so if you have to add several Views that look the same do this
Make an XML with your views
In the loop where you are adding the several Views, inflate this xml, set your id's etc, and add them
You can have all the basics, styles etc in your XML, and still add stuff dynamically.
Maybe you want to check out some of the hello world code?
You can't build apps in XML. You use XML to define the UI and a few other things, but the logic of the app itself has to be written in Java.
Android development is in Java, but when you declare the layouts (where the buttons and so are going to be on the screen) you do that in XML.
So you have to use BOTH anyways.
XML for layout
JAVA for programming your app

Categories

Resources