Added in API level 21

LayoutParams


open class LayoutParams : ActionBar.LayoutParams

Layout information for child views of Toolbars.

Toolbar.LayoutParams extends ActionBar.LayoutParams for compatibility with existing ActionBar API. See Activity.setActionBar for more info on how to use a Toolbar as your Activity's ActionBar.

Summary

XML attributes
android:layout_gravity Standard gravity constant that a child supplies to its parent.
Inherited XML attributes
android:layout_gravity

Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.

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

LayoutParams(gravity: Int)

LayoutParams(width: Int, height: Int)

LayoutParams(width: Int, height: Int, gravity: 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.

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 gravity

Gravity for the view associated with these LayoutParams.

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_gravity

android:layout_gravity
Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.

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.

Public constructors

LayoutParams

Added in API level 21
LayoutParams(source: ActionBar.LayoutParams!)

LayoutParams

Added in API level 21
LayoutParams(
    c: Context,
    attrs: AttributeSet!)
Parameters
c Context: This value cannot be null.

LayoutParams

Added in API level 21
LayoutParams(source: ViewGroup.LayoutParams!)

LayoutParams

Added in API level 21
LayoutParams(source: ViewGroup.MarginLayoutParams!)

LayoutParams

Added in API level 21
LayoutParams(source: Toolbar.LayoutParams!)

LayoutParams

Added in API level 21
LayoutParams(gravity: Int)

LayoutParams

Added in API level 21
LayoutParams(
    width: Int,
    height: Int)

LayoutParams

Added in API level 21
LayoutParams(
    width: Int,
    height: Int,
    gravity: Int)

Develop your UI on Android.

Updated Feb 22, 2024

Discover the latest app development tools, platform updates, training, and documentation for developers across every Android device.

Updated Dec 18, 2024

Welcome to Android 4.3, a sweeter version of Jelly Bean! Android 4.3 includes performance optimizations and great new features for users and developers. This document provides a glimpse of what's new for developers. See the Android 4.3 APIs document…

Updated May 20, 2024