Added in API level 14

LayoutParams


open class LayoutParams : ViewGroup.MarginLayoutParams

Layout information associated with each of the children of a GridLayout.

GridLayout supports both row and column spanning and arbitrary forms of alignment within each cell group. The fundamental parameters associated with each cell group are gathered into their vertical and horizontal components and stored in the rowSpec and columnSpec layout parameters. Specs are immutable structures and may be shared between the layout parameters of different children.

The row and column specs contain the leading and trailing indices along each axis and together specify the four grid indices that delimit the cells of this cell group.

The alignment properties of the row and column specs together specify both aspects of alignment within the cell group. It is also possible to specify a child's alignment within its cell group by using the GridLayout.LayoutParams.setGravity(int) method.

The weight property is also included in Spec and specifies the proportion of any excess space that is due to the associated view.

WRAP_CONTENT and MATCH_PARENT

Because the default values of the width and height properties are both WRAP_CONTENT, this value never needs to be explicitly declared in the layout parameters of GridLayout's children. In addition, GridLayout does not distinguish the special size value MATCH_PARENT from WRAP_CONTENT. A component's ability to expand to the size of the parent is instead controlled by the principle of flexibility, as discussed in GridLayout.

Summary

You should not need to use either of the special size values: WRAP_CONTENT or MATCH_PARENT when configuring the children of a GridLayout.

Default values

See GridLayout for a more complete description of the conventions used by GridLayout in the interpretation of the properties of this class.

Summary

XML attributes
android:layout_column The column boundary delimiting the left of the group of cells occupied by this view.
android:layout_columnSpan The column span: the difference between the right and left boundaries delimiting the group of cells occupied by this view.
android:layout_columnWeight The relative proportion of horizontal space that should be allocated to this view during excess space distribution.
android:layout_gravity Gravity specifies how a component should be placed in its group of cells.
android:layout_row The row boundary delimiting the top of the group of cells occupied by this view.
android:layout_rowSpan The row span: the difference between the top and bottom boundaries delimiting the group of cells occupied by this view.
android:layout_rowWeight The relative proportion of vertical space that should be allocated to this view during excess space distribution.
Inherited XML attributes
android:layout_height

Specifies the basic height of the view. This is a required attribute for any view inside of a containing layout manager. Its value may be a dimension (such as "12dip") for a constant height or one of the special constants.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Must be one of the following constant values.

Constant Value Description
fill_parent ffffffff The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parent ffffffff The view should be as big as its parent (minus padding). Introduced in API Level 8.
wrap_content fffffffe The view should be only big enough to enclose its content (plus padding).

android:layout_width

Specifies the basic width of the view. This is a required attribute for any view inside of a containing layout manager. Its value may be a dimension (such as "12dip") for a constant width or one of the special constants.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Must be one of the following constant values.

Constant Value Description
fill_parent ffffffff The view should be as big as its parent (minus padding). This constant is deprecated starting from API Level 8 and is replaced by match_parent.
match_parent ffffffff The view should be as big as its parent (minus padding). Introduced in API Level 8.
wrap_content fffffffe The view should be only big enough to enclose its content (plus padding).

android:layout_margin

Specifies extra space on the left, top, right and bottom sides of this view. If both layout_margin and any of layout_marginLeft, layout_marginRight, layout_marginStart, layout_marginEnd, layout_marginTop, and layout_marginBottom are also specified, the layout_margin value will take precedence over the edge-specific values. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginBottom

Specifies extra space on the bottom side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginEnd

Specifies extra space on the end side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginHorizontal

Specifies extra space on the left and right sides of this view. Specifying layout_marginHorizontal is equivalent to specifying layout_marginLeft and layout_marginRight. If both layout_marginHorizontal and either/both of layout_marginLeft and layout_marginRight are also specified, the layout_marginHorizontal value will take precedence over the edge-specific values. Also, layout_margin will always take precedence over any of these values, including layout_marginHorizontal. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginLeft

Specifies extra space on the left side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginRight

Specifies extra space on the right side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginStart

Specifies extra space on the start side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginTop

Specifies extra space on the top side of this view. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:layout_marginVertical

Specifies extra space on the top and bottom sides of this view. Specifying layout_marginVertical is equivalent to specifying layout_marginTop and layout_marginBottom with that same value. If both layout_marginVertical and either/both of layout_marginTop and layout_marginBottom are also specified, the layout_marginVertical value will take precedence over the edge-specific values. Also, layout_margin will always take precedence over any of these values, including layout_marginVertical. This space is outside this view's bounds. Margin values should be positive.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Inherited constants
Int FILL_PARENT

Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT.

Int MATCH_PARENT

Special value for the height or width requested by a View. MATCH_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. Introduced in API Level 8.

Int WRAP_CONTENT

Special value for the height or width requested by a View. WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account.

Public constructors

Constructs a new LayoutParams with default values as defined in LayoutParams.

LayoutParams(context: Context!, attrs: AttributeSet!)

Values not defined in the attribute set take the default values defined in LayoutParams.

Copy constructor.

LayoutParams(rowSpec: GridLayout.Spec!, columnSpec: GridLayout.Spec!)

Constructs a new LayoutParams instance for this rowSpec and columnSpec.

Public methods
open Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

open Int

open Unit
setGravity(gravity: Int)

Describes how the child views are positioned.

Protected methods
open Unit
setBaseAttributes(attributes: TypedArray!, widthAttr: Int, heightAttr: Int)

Inherited functions
Int getLayoutDirection()

Retuns the layout direction. Can be either View.LAYOUT_DIRECTION_LTR or View.LAYOUT_DIRECTION_RTL.

Int getMarginEnd()

Returns the end margin in pixels.

Int getMarginStart()

Returns the start margin in pixels.

Boolean isMarginRelative()

Check if margins are relative.

Unit resolveLayoutDirection(layoutDirection: Int)

This will be called by android.view.View#requestLayout(). Left and Right margins may be overridden depending on layout direction.

Unit setLayoutDirection(layoutDirection: Int)

Set the layout direction

Unit setMarginEnd(end: Int)

Sets the relative end margin. Margin values should be positive.

Unit setMarginStart(start: Int)

Sets the relative start margin. Margin values should be positive.

Unit setMargins(left: Int, top: Int, right: Int, bottom: Int)

Sets the margins, in pixels. A call to android.view.View#requestLayout() needs to be done so that the new margins are taken into account. Left and right margins may be overridden by android.view.View#requestLayout() depending on layout direction. Margin values should be positive.

Unit setBaseAttributes(a: TypedArray!, widthAttr: Int, heightAttr: Int)

Extracts the layout parameters from the supplied attributes.

Properties
GridLayout.Spec!

The spec that defines the horizontal characteristics of the cell group described by these layout parameters.

GridLayout.Spec!

The spec that defines the vertical characteristics of the cell group described by these layout parameters.

Inherited properties
Int bottomMargin

The bottom margin in pixels of the child. Margin values should be positive. Call ViewGroup.setLayoutParams(LayoutParams) after reassigning a new value to this field.

Int leftMargin

The left margin in pixels of the child. Margin values should be positive. Call ViewGroup.setLayoutParams(LayoutParams) after reassigning a new value to this field.

Int rightMargin

The right margin in pixels of the child. Margin values should be positive. Call ViewGroup.setLayoutParams(LayoutParams) after reassigning a new value to this field.

Int topMargin

The top margin in pixels of the child. Margin values should be positive. Call ViewGroup.setLayoutParams(LayoutParams) after reassigning a new value to this field.

Int height

Information about how tall the view wants to be. Can be one of the constants FILL_PARENT (replaced by MATCH_PARENT in API Level 8) or WRAP_CONTENT, or an exact size.

LayoutAnimationController.AnimationParameters! layoutAnimationParameters

Used to animate layouts.

Int width

Information about how wide the view wants to be. Can be one of the constants FILL_PARENT (replaced by MATCH_PARENT in API Level 8) or WRAP_CONTENT, or an exact size.

XML attributes

android:layout_column

android:layout_column
The column boundary delimiting the left of the group of cells occupied by this view.

May be an integer value, such as "100".

android:layout_columnSpan

android:layout_columnSpan
The column span: the difference between the right and left boundaries delimiting the group of cells occupied by this view. The default is one. See android.widget.GridLayout.Spec.

May be an integer value, such as "100".

android:layout_columnWeight

android:layout_columnWeight
The relative proportion of horizontal space that should be allocated to this view during excess space distribution.

May be a floating point value, such as "1.2".

android:layout_gravity

android:layout_gravity
Gravity specifies how a component should be placed in its group of cells. The default is LEFT | BASELINE. See android.widget.GridLayout.LayoutParams#setGravity(int).

Must be one or more (separated by '|') of the following constant values.

Constant Value Description
bottom 50 Push object to the bottom of its container, not changing its size.
center 11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
center_horizontal 1 Place object in the horizontal center of its container, not changing its size.
center_vertical 10 Place object in the vertical center of its container, not changing its size.
clip_horizontal 8 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
clip_vertical 80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
end 800005 Push object to the end of its container, not changing its size.
fill 77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
fill_horizontal 7 Grow the horizontal size of the object if needed so it completely fills its container.
fill_vertical 70 Grow the vertical size of the object if needed so it completely fills its container.
left 3 Push object to the left of its container, not changing its size.
right 5 Push object to the right of its container, not changing its size.
start 800003 Push object to the beginning of its container, not changing its size.
top 30 Push object to the top of its container, not changing its size.

android:layout_row

android:layout_row
The row boundary delimiting the top of the group of cells occupied by this view.

May be an integer value, such as "100".

android:layout_rowSpan

android:layout_rowSpan
The row span: the difference between the top and bottom boundaries delimiting the group of cells occupied by this view. The default is one. See android.widget.GridLayout.Spec.

May be an integer value, such as "100".

android:layout_rowWeight

android:layout_rowWeight
The relative proportion of vertical space that should be allocated to this view during excess space distribution.

May be a floating point value, such as "1.2".

Public constructors

LayoutParams

Added in API level 14
LayoutParams()

Constructs a new LayoutParams with default values as defined in LayoutParams.

LayoutParams

Added in API level 14
LayoutParams(
    context: Context!,
    attrs: AttributeSet!)

Values not defined in the attribute set take the default values defined in LayoutParams.

LayoutParams

Added in API level 14
LayoutParams(params: ViewGroup.LayoutParams!)

LayoutParams

Added in API level 14
LayoutParams(params: ViewGroup.MarginLayoutParams!)

LayoutParams

Added in API level 14
LayoutParams(source: GridLayout.LayoutParams!)

Copy constructor. Clones the width, height, margin values, row spec, and column spec of the source.

Parameters
source GridLayout.LayoutParams!: The layout params to copy from.

LayoutParams

Added in API level 14
LayoutParams(
    rowSpec: GridLayout.Spec!,
    columnSpec: GridLayout.Spec!)

Constructs a new LayoutParams instance for this rowSpec and columnSpec. All other fields are initialized with default values as defined in LayoutParams.

Parameters
rowSpec GridLayout.Spec!: the rowSpec
columnSpec GridLayout.Spec!: the columnSpec

Public methods

equals

Added in API level 14
open fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
o This value may be null.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

hashCode

Added in API level 14
open fun hashCode(): Int
Return
Int a hash code value for this object.

setGravity

Added in API level 14
open fun setGravity(gravity: Int): Unit

Describes how the child views are positioned. Default is LEFT | BASELINE. See Gravity.

Parameters
gravity Int: the new gravity value

Protected methods

setBaseAttributes

Added in API level 14
protected open fun setBaseAttributes(
    attributes: TypedArray!,
    widthAttr: Int,
    heightAttr: Int
): Unit
Parameters
a the style attributes to extract the parameters from
widthAttr Int: the identifier of the width attribute
heightAttr Int: the identifier of the height attribute

Properties

columnSpec

Added in API level 14
var columnSpec: GridLayout.Spec!

The spec that defines the horizontal characteristics of the cell group described by these layout parameters. If an assignment is made to this field after a measurement or layout operation has already taken place, a call to ViewGroup.setLayoutParams(ViewGroup.LayoutParams) must be made to notify GridLayout of the change. GridLayout is normally able to detect when code fails to observe this rule, issue a warning and take steps to compensate for the omission. This facility is implemented on a best effort basis and should not be relied upon in production code - so it is best to include the above calls to remove the warnings as soon as it is practical.

rowSpec

Added in API level 14
var rowSpec: GridLayout.Spec!

The spec that defines the vertical characteristics of the cell group described by these layout parameters. If an assignment is made to this field after a measurement or layout operation has already taken place, a call to ViewGroup.setLayoutParams(ViewGroup.LayoutParams) must be made to notify GridLayout of the change. GridLayout is normally able to detect when code fails to observe this rule, issue a warning and take steps to compensate for the omission. This facility is implemented on a best effort basis and should not be relied upon in production code - so it is best to include the above calls to remove the warnings as soon as it is practical.