Android Programming Layouts
Layouts in Android Programming
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:
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.
Instantiate layout elements at runtime
- Your application can create View and ViewGroup objects ( and manipulate their properties) programmatically.
Common Android Programming Layouts are
- Linear Layout
- Relative Layout
- Web View
- Table Layout
- Frame Layout
- LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android: orientation
- All children of a Linear Layout are stacked one after the other, so a vertical list will only have one child per row, no matter how wide they are, and a horizontal list will only be one row high (the height of the tallest child, plus padding).
- A Linear Layout respects margins between children and the gravity (right, center, or left alignment) of each child.
- A relative Layout 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 Relative Layout area (such as aligned to the bottom, left or center).
- Relative Layout lets child views specify their position relative to the parent view or to each other (specified by ID).
- So you can align two elements with a right border, or make one below another, centered in the screen, centered left, and so on.
- By default, all child views are drawn at the top-left of the layout, so you must define the position of each view using the various layout properties available from RelativeLayout.LayoutParams.
- Frame Layout is designed to block out an area on the screen to display a single item.
- Generally, Frame Layout should be used to hold a single child view, because it can be difficult to organize child views in a way that’s scalable to different screen sizes without the children overlapping each other.
- Also, You can, however, add multiple children to a Frame Layout and control their position within the Frame Layout by assigning gravity to each child, using the android:layout_gravity attribute.
- A table Android Programming Layouts that arranges its children into rows and columns.
- A Table Layout consists of a number of TableRow objects, each defining a row (actually, you can have other children, which will be explained below).
- Table Layout containers do not display border lines for their rows, columns, or cells.
- Also, Each row has zero or more cells; each cell can hold one View object.
- Moreover, The table has as many columns as the row with the most cells
- A table can leave cells empty.
- Cells can span columns, as they can in HTML.