Amazon Gift Cards

Friday, January 2, 2009

AbsoluteLayout in Android (XML)

AbsoluteLayout is the layout that you may want if you want to specify the x and y, in html its position:absolute, and the x(top) and y(left) is android:layout_x and android:layout_y. By looking at this, you can see that there are 5 possible value. Yet in our example i'm going to give you 4 coz i cant successful run the 5th one.
<?xml version="1.0" encoding="utf-8"?> 
  xmlns:android=""   android:orientation="vertical"   android:layout_width="fill_parent"   android:layout_height="fill_parent" >   <Button android:id="@+id/pixelsBtn"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Pixels"     android:layout_y="50px"     android:layout_x="80px">   </Button>   <Button android:id="@+id/scaledBtn"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Scaled"     android:layout_y="100px"     android:layout_x="80sp">   </Button>   <Button android:id="@+id/inchesBtn"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Inches"     android:layout_y="150px"     android:layout_x="0.5in">   </Button>   <Button android:id="@+id/millimetersBtn"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="Milli Meters"     android:layout_y="200px"     android:layout_x="8mm">   </Button> </AbsoluteLayout>

Quick Explanation
Here we just specify the x and y, by looking at this you would logically understand what they mean.

Here is how you can set this as your layout in your java code

absoluteLayout in android

Update History
   Jan 17, 2012 - Visual Update


Anonymous said...

Excellent article; short, sweet, and best of all accurate. Keep up the great work!

Anonymous said...

Not a good example.if screen short is avaLaval then it will be better.