The Android Developer Challenge is back! Submit your idea before December 2.

MarginLayoutParamsCompat

class MarginLayoutParamsCompat
kotlin.Any
   ↳ androidx.core.view.MarginLayoutParamsCompat

Helper for accessing API features in MarginLayoutParams in a backwards compatible way.

Summary

Public methods

static Int

Returns the layout direction.

static Int

Get the relative ending margin that was set.

static Int

Get the relative starting margin that was set.

static Boolean

Check if margins are relative.

static Unit

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

static Unit
setLayoutDirection(lp: MarginLayoutParams!, layoutDirection: Int)

Set the layout direction.

static Unit
setMarginEnd(lp: MarginLayoutParams!, marginEnd: Int)

Set the relative end margin.

static Unit
setMarginStart(lp: MarginLayoutParams!, marginStart: Int)

Set the relative start margin.

Public methods

getLayoutDirection

static fun getLayoutDirection(lp: MarginLayoutParams!): Int

Returns the layout direction. Can be either ViewCompat#LAYOUT_DIRECTION_LTR or ViewCompat#LAYOUT_DIRECTION_RTL.

Return
Int: the layout direction.

getMarginEnd

static fun getMarginEnd(lp: MarginLayoutParams!): Int

Get the relative ending margin that was set.

On platform versions supporting bidirectional text and layouts this value will be resolved into the LayoutParams object's left or right margin as appropriate when the associated View is attached to a window or when the layout direction of that view changes.

Parameters
lp MarginLayoutParams!: LayoutParams to query
Return
Int: the margin along the ending edge in pixels

getMarginStart

static fun getMarginStart(lp: MarginLayoutParams!): Int

Get the relative starting margin that was set.

On platform versions supporting bidirectional text and layouts this value will be resolved into the LayoutParams object's left or right margin as appropriate when the associated View is attached to a window or when the layout direction of that view changes.

Parameters
lp MarginLayoutParams!: LayoutParams to query
Return
Int: the margin along the starting edge in pixels

isMarginRelative

static fun isMarginRelative(lp: MarginLayoutParams!): Boolean

Check if margins are relative.

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

resolveLayoutDirection

static fun resolveLayoutDirection(lp: MarginLayoutParams!, layoutDirection: Int): Unit

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

setLayoutDirection

static fun setLayoutDirection(lp: MarginLayoutParams!, layoutDirection: Int): Unit

Set the layout direction.

Parameters
layoutDirection MarginLayoutParams!: the layout direction. Should be either ViewCompat#LAYOUT_DIRECTION_LTR or ViewCompat#LAYOUT_DIRECTION_RTL.

setMarginEnd

static fun setMarginEnd(lp: MarginLayoutParams!, marginEnd: Int): Unit

Set the relative end margin.

On platform versions supporting bidirectional text and layouts this value will be resolved into the LayoutParams object's left or right margin as appropriate when the associated View is attached to a window or when the layout direction of that view changes.

Parameters
lp MarginLayoutParams!: LayoutParams to query
marginEnd MarginLayoutParams!: the desired end margin in pixels

setMarginStart

static fun setMarginStart(lp: MarginLayoutParams!, marginStart: Int): Unit

Set the relative start margin.

On platform versions supporting bidirectional text and layouts this value will be resolved into the LayoutParams object's left or right margin as appropriate when the associated View is attached to a window or when the layout direction of that view changes.

Parameters
lp MarginLayoutParams!: LayoutParams to query
marginStart MarginLayoutParams!: the desired start margin in pixels