Layouts in android Layouts in android Layouts in android
Layouts in android Layouts in android Layouts in android
LAYOUTS IN ANDROID
Android UI Layouts
ViewGroup.
As we know, an android application contains a large number of
ViewGroup objects.
View
android:layout_marginLeft
Used to declare the extra space used on the left side of View and ViewGroup
elements.
android:layout_marginRight
Used to declare the extra space used on the right side of View and ViewGroup
elements.
android:layout_marginTop
Used to declare the extra space used in the top side of View and ViewGroup
elements.
Different Attribute of the Layouts
android:id
Used to specify the id of the view.
android:layout_width
Used to declare the width of View and ViewGroup elements in the
layout.
android:layout_height
Used to declare the height of View and ViewGroup elements in the
layout.
Different Attribute of the Layouts
android:layout_marginBottom
Used to declare the extra space used in the bottom side of View
and ViewGroup elements.
android:layout_gravity
Used to define how child Views are positioned in the layout.
LinearLayout
android:id
android:baselineAligned
This must be a boolean value, either "true" or "false" and prevents the
layout from aligning its children's baselines.
android:baselineAlignedChildIndex
android:divider
android:gravity
This specifies how an object should position its content, on both the X
and Y axes. Possible values are top, bottom, left, right, center,
center_vertical, center_horizontal etc.
LinearLayout Attributes
android:orientation
android:weightSum
android:orientation= "horizontal"
RelativeLayout
android:id
android:gravity
This specifies how an object should position its content, on both the X
and Y axes. Possible values are top, bottom, left, right, center,
center_vertical, center_horizontal etc.
android:ignoreGravity
layout_alignParentLeft
It is set “true” to match the left edge of view to the left edge of parent.
layout_alignParentRight
It is set “true” to match the right edge of view to the right edge of
parent.
layout_alignParentTop
It is set “true” to match the top edge of view to the top edge of parent.
layout_alignParentBottom
It is set “true” to match the bottom edge of view to the bottom edge of
parent.
Important Attributes for
positioning
layout_alignLeft
It accepts another sibling view id and align the view to the left of the
specified view id.
layout_alignRight
It accepts another sibling view id and align the view to the right of the
specified view id.
layout_alignStart
It accepts another sibling view id and align the view to start of the
specified view id.
layout_alignEnd
It accepts another sibling view id and align the view to end of specified
view id.
Important Attributes for
positioning
layout_centerInParent
When it is set “true”, the view will be aligned to the center of parent.
layout_centerHorizontal
When it is set “true”, the view will be vertically centre aligned within
its parent.
res/values/strings.xml
ConstraintLayout
android:id
This attribute is used to constrain the view with respect to the left
position.
Important Attributes of ConstraintLayout
app:layout_constraintRight_toRightOf
app:layout_constraintTop_toTopOf
This attribute is used to constrain the view with respect to the top
position.
Advantages of using ConstraintLayout
your UI with the drag and drop feature provided by the Android
Studio design editor.
It helps to improve the UI performance over other layouts.
android:foreground
This defines the drawable to draw over the content and possible values
may be a color value, in the form of "#rgb", "#argb", "#rrggbb", or
"#aarrggbb".
android:foregroundGravity
android:measureAllChildren
View object.
TableLayout containers do not display border lines for
android:collapseColumns
This specifies the zero-based index of the columns to collapse. The column
indices must be separated by a comma: 1, 2, 5.
android:shrinkColumns
The zero-based index of the columns to shrink. The column indices must be
separated by a comma: 1, 2, 5.
android:stretchColumns
The zero-based index of the columns to stretch. The column indices must be
separated by a comma: 1, 2, 5.
Absolute Layout
android:id
android:layout_x
android:layout_y
android:id
android:columnWidth
This specifies the fixed width for each column. This could be in px, dp,
sp, in, or mm.
android:gravity
Specifies the gravity within each cell. Possible values are top, bottom,
left, right, center, center_vertical, center_horizontal etc.
GridView Attributes
android:horizontalSpacing
android:numColumns
android:stretchMode
Defines how columns should stretch to fill the available empty space, if
any. This must be either of the values −
none − Stretching is disabled.
spacingWidth − The spacing between each column is stretched.
columnWidth − Each column is stretched equally.
spacingWidthUniform − The spacing between each column is
uniformly stretched..
GridView Attributes
android:verticalSpacing
Defines the default vertical spacing between rows. This could be in px,
dp, sp, in, or mm.
ListView
column.
The list items are automatically inserted to the list using
the view can takes the data from adapter view and shows
the data on different views like as spinner, list view, grid
view etc.
ListView Attributes
android:id
android:divider
android:dividerHeight
This specifies height of the divider. This could be in px, dp, sp, in, or mm.
android:entries
Specifies the reference to an array resource that will populate the ListView.
ListView Attributes
android:footerDividersEnabled
When set to false, the ListView will not draw the divider before each
footer view. The default value is true.
android:headerDividersEnabled
When set to false, the ListView will not draw the divider after each
header view. The default value is true..