Added in API level 1

MarginLayoutParams


open class MarginLayoutParams : ViewGroup.LayoutParams
ActionBar.LayoutParams

Per-child layout information associated with action bar custom views.

FrameLayout.LayoutParams

Per-child layout information for layouts that support margins.

GridLayout.LayoutParams

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

LinearLayout.LayoutParams

Per-child layout information associated with ViewLinearLayout.

RelativeLayout.LayoutParams

Specifies how a view is positioned within a RelativeLayout.

ActionMenuView.LayoutParams

RadioGroup.LayoutParams

This set of layout parameters defaults the width and the height of the children to WRAP_CONTENT when they are not specified in the XML file.

TableLayout.LayoutParams

This set of layout parameters enforces the width of each child to be MATCH_PARENT and the height of each child to be WRAP_CONTENT, but only if the height is not specified.

TableRow.LayoutParams

Set of layout parameters used in table rows.

Toolbar.LayoutParams

Layout information for child views of Toolbars.

Per-child layout information for layouts that support margins. See ViewGroup Margin Layout Attributes for a list of all child view attributes that this class supports.

Summary

XML attributes
android:layout_margin Specifies extra space on the left, top, right and bottom sides of this view.
android:layout_marginBottom Specifies extra space on the bottom side of this view.
android:layout_marginEnd Specifies extra space on the end side of this view.
android:layout_marginHorizontal Specifies extra space on the left and right sides of this view.
android:layout_marginLeft Specifies extra space on the left side of this view.
android:layout_marginRight Specifies extra space on the right side of this view.
android:layout_marginStart Specifies extra space on the start side of this view.
android:layout_marginTop Specifies extra space on the top side of this view.
android:layout_marginVertical Specifies extra space on the top and bottom sides of this view.
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).

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

Creates a new set of layout parameters.

Copy constructor.

MarginLayoutParams(width: Int, height: Int)

Public methods
open Int

Retuns the layout direction.

open Int

Returns the end margin in pixels.

open Int

Returns the start margin in pixels.

open Boolean

Check if margins are relative.

open Unit
resolveLayoutDirection(layoutDirection: Int)

This will be called by android.view.View#requestLayout().

open Unit
setLayoutDirection(layoutDirection: Int)

Set the layout direction

open Unit

Sets the relative end margin.

open Unit

Sets the relative start margin.

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

Sets the margins, in pixels.

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

Extracts the layout parameters from the supplied attributes.

Properties
Int

The bottom margin in pixels of the child.

Int

The left margin in pixels of the child.

Int

The right margin in pixels of the child.

Int

The top margin in pixels of the child.

Inherited properties
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_margin

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

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

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

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

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

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

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

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

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).

Public constructors

MarginLayoutParams

Added in API level 1
MarginLayoutParams(
    c: Context!,
    attrs: AttributeSet!)

Creates a new set of layout parameters. The values are extracted from the supplied attributes set and context.

Parameters
c Context!: the application environment
attrs AttributeSet!: the set of attributes from which to extract the layout parameters' values

MarginLayoutParams

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

MarginLayoutParams

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

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

Parameters
source ViewGroup.MarginLayoutParams!: The layout params to copy from.

MarginLayoutParams

Added in API level 1
MarginLayoutParams(
    width: Int,
    height: Int)

Public methods

getLayoutDirection

Added in API level 17
open fun getLayoutDirection(): Int

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

Return
Int the layout direction.

getMarginEnd

Added in API level 17
open fun getMarginEnd(): Int

Returns the end margin in pixels.

Return
Int the end margin in pixels.

getMarginStart

Added in API level 17
open fun getMarginStart(): Int

Returns the start margin in pixels.

Return
Int the start margin in pixels.

isMarginRelative

Added in API level 17
open fun isMarginRelative(): Boolean

Check if margins are relative.

Return
Boolean true if either marginStart or marginEnd has been set.

resolveLayoutDirection

Added in API level 17
open fun resolveLayoutDirection(layoutDirection: Int): Unit

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

Parameters
layoutDirection Int: the direction of the layout View.LAYOUT_DIRECTION_LTR View.LAYOUT_DIRECTION_RTL

setLayoutDirection

Added in API level 17
open fun setLayoutDirection(layoutDirection: Int): Unit

Set the layout direction

Parameters
layoutDirection Int: the layout direction. Should be either View.LAYOUT_DIRECTION_LTR or View.LAYOUT_DIRECTION_RTL.

setMarginEnd

Added in API level 17
open fun setMarginEnd(end: Int): Unit

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

Parameters
end Int: the end margin size

setMarginStart

Added in API level 17
open fun setMarginStart(start: Int): Unit

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

Parameters
start Int: the start margin size

setMargins

Added in API level 1
open fun setMargins(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit

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.

Parameters
left Int: the left margin size
top Int: the top margin size
right Int: the right margin size
bottom Int: the bottom margin size

Properties

bottomMargin

Added in API level 1
var bottomMargin: Int

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.

leftMargin

Added in API level 1
var leftMargin: Int

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.

rightMargin

Added in API level 1
var rightMargin: Int

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.

topMargin

Added in API level 1
var topMargin: Int

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.