Sunday, 13 January 2013

Android Layouts

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:

-->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.

-->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:
If "true", makes the top edge of this view match the top edge of the parent.

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

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

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

-->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

-->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.

A layout that places its children in a rectangular grid.

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