Saturday, December 1, 2012

Android App Development 101 1st tutorial, Learning xml attributes

Xml's are huge in android. You can accomplish lots of things using just xmls from animations to layouts. Besides xml lets you create your layout without writing any java code and see how it looks on a emulator or an actual device. In this post i will be talking about some of the basic xml attributes. These attributes will be frequently used in upcoming tutorials.


The ids should be unique for each object whether its a button, textView, imageView or videoView. Unique ids are important when we have to reference that particular object in our java class.

android:height="x" and android:width="x"
x= xdp, wrap_content, fill_parent etc

wrap_content as the name suggest wraps the object and fill_parent fills the whole layout.

android:gravity = "x"
x = top, bottom,center,left,right etc

gravity attribute is used to locate the object in the layout.

android:onClick ="yourMethod"

onClick is another important attribute. For eg a button is given an onClick attribute. What is does is when the user clicks on that button, it runs the method that was listed in the xml in your java class file.


android:background="your color"

your color can use various formats. I like using the html color codes. For eg white would be #FFFFFF

you can find other color codes here.

There are lot more attributes, i will explain those as they come along.

No comments:

Post a Comment