Sunday, 13 January 2013

Android Layouts


layout:
--------
A layout defines the visual structure for a user interface, such as the UI for an activity or app widget.
You can declare a layout in two ways:

1.Declare UI elements in XML.
---------------------------
Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses,
such as those for widgets and layouts.

2.Instantiate layout elements at runtime.
----------------------------------------
Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.


===>The advantage to declaring your UI in XML is that it enables you to better
separate the presentation of your application from the code that controls its behavior.


All types of Layouts:
-----------------------
1.LinearLayout
2.RelativeLayout
3.TableLayout
4.FrameLayout
5.GridLayout
6.AbsoluteLayout
7.AlterLayout

1.LinearLayout:
---------------
-->The LinearLayout arranges views in a single column or a single row. Child views can be arranged either vertically or horizontally.
-->You can specify the layout direction with the android:orientation attribute.


2.RelativeLayout:
----------------
-->RelativeLayout is a view group that displays child views in relative positions.
-->The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view)
or in positions relative to the parent RelativeLayout area
(such as aligned to the bottom, left of center).

-->A RelativeLayout is a very powerful utility for designing a user interface
because it can eliminate nested view groups and keep your layout hierarchy flat,
 which improves performance.

-->If you find yourself using several nested LinearLayout groups,
you may be able to replace them with a single RelativeLayout.

Some of RelativeLayout Properties:
-----------------------------------
android:layout_alignParentTop:
If "true", makes the top edge of this view match the top edge of the parent.

android:layout_centerVertical:
If "true", centers this child vertically within its parent.

android:layout_below:
Positions the top edge of this view below the view specified with a resource ID.

android:layout_toRightOf:
Positions the left edge of this view to the right of the view specified with a resource ID…etc...



3.TableLayout:
------------------
-->The TableLayout groups view into rows and columns.
You use the <TableRow> element to designate a row in the table.

-->Each row can contain one or more views

4.FrameLayout:
---------------
-->The FrameLayout is a place holder on screen that you can use to display
a single view.
-->Views that you add to a FrameLayout are always anchored to the
 top left of the layout.

5.GridLayout:
-------------
A layout that places its children in a rectangular grid.

6.AbsoluteLayout:
-----------------
The AbsoluteLayout enables you to specify the exact location of its children .