Search This Blog

Showing posts with label Layouts. Show all posts
Showing posts with label Layouts. Show all posts

Wednesday, 6 June 2012

Quick Layout Tutorial for Android


 Layout Basics


A user interface template drawn on the screen. This templates can be managed using XML files in android and stored  in res/layout directory for the application. A group of controls defined and organized in the user interface

An Android layout is a class that handles the screen arrangements for this child elements.  Anything that is a View (or inherits from View) can be a child of a layout.

You can nest the layout and you can create the custom layouts by inherit from ViewGroup.
  following is the list of standard layouts

AbsoluteLayout
FrameLayout

LinearLayout

RelativeLayout

TableLayout


This post is explaining the AbsoluteLayout

AbsoluteLayout places each control at an absolute position. The exact x and y positions need specify for each control.

The Absolute Layout is difficult to maintain for most of the UIs as adding a new control is not flexible in the absolute layouts.

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
     android:layout_x="10px"
     android:layout_y="110px"
     android:text="Layout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:layout_x="150px"
     android:layout_y="110px"
     android:text="Absolute layout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
  </AbsoluteLayout>
 
Each control specify a x and y positions by android:layout_x and android:layout_y.
Android defines the top left of the screen as (0,0) and x coordinate move from 
left to right and y move from top to bottom. 
 
See the screen shot here for above example.
 
Absolute layout