You are on page 1of 14

LAYOUT MANAGER

➢The basic building block for user interface is a View


object which is created from the View class and
occupies a rectangular area on the screen and is
responsible for drawing and event handling.
➢View is the base class for widgets, which are used to
create interactive UI components like buttons, text
fields, etc.
➢The ViewGroup is a subclass of View and provides
invisible container that hold other Views or other
ViewGroups and define their layout properties.
➢At third level we have different layouts
which are subclasses of ViewGroup class and a
typical layout defines the visual structure for
an Android user interface
➢Each layouts (or layout managers)
implements a specific strategy to manage the
size and position of its children
➢A layout can be created using a simple XML
file main_layout.xml which is located in the
res/layout folder.
TYPES
➢Linear Layout
➢Relative Layout
➢Table Layout
➢Grid Layout
➢Frame Layout
ATTRIBUTES
➢Each layout has a set of attributes which
define the visual properties of that layout.
➢There are few common attributes among all
the layouts and their are other attributes
which are specific to that layout
THE LINEARLAYOUT MANAGER

➢Android LinearLayout is a view group that


aligns all children in either vertically or
horizontally
➢The layout direction can be specified with
the android:orientation attribute
➢android.widget.LinearLayout
➢Layout Weight
◦ LinearLayout also supports assigning a weight to individual
children with the
android:layout_weight attribute.
◦ This attribute assigns an "importance" value to a view in terms
of how much
space it should occupy on the screen
◦ To create a linear layout in which each child uses the same
amount of space on
the screen,
◦ set the android:layout_height of each view to "0dp" (for a
vertical layout)
or the android:layout_width of each view to "0dp" (for a
horizontal layout).
◦ Then set the android:layout_weight of each view to "1".
➢android:divider
➢This is drawable to use as a vertical divider between buttons
➢android:weightSum: Sum up of child weight
TABLE LAYOUT
➢In Android, Table Layout is used
to arrange the group of views into
rows and columns.
➢ Table Layout containers do not
display a border line for their
columns, rows or cells
➢<TableRow> element to build a
row in the table
➢ Each row has zero or more
cells; each cell can hold one
View object.
THE RELATIVE LAYOUT
 ➢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 or center).
 ➢Several nested LinearLayout groups, can be replaced with a single
RelativeLayout
 ➢Properties available from RelativeLayout.LayoutParams
 ➢android:layout_above,android:layout_alignBottom,
android:layout_alignLeft,
 android:layout_alignParentBottom, android:layout_alignParentEnd,
 android:layout_alignParentLeft, android:layout_alignParentRight,
 android:layout_alignParentStart, android:layout_alignParentTop
THE FRAME LAYOUT
➢ A layout manager that is mainly used to display a
single item
➢This layout class is used to dynamically display a
single view, but it can be
populated with many items, setting one to visible while
the others are invisible
➢FrameLayout is designed to block out an area on the
screen to display a single child view
➢Child views are drawn in a stack, with the most
recently added child on top.
➢ The size of the FrameLayout is the size of its largest
child (plus padding),
visible or not (if the FrameLayout's parent permits)
GRIDLAYOUT
➢A layout that places its children in a
rectangular grid.
➢The grid is composed of a set of infinitely
thin lines that separate the viewing
area into cells.
➢ Throughout the API, grid lines are
referenced by grid indices. A grid with N
columns has N + 1 grid indices that run from 0
through N

You might also like