MarginLayoutParamsCompat

Added in 1.1.0

public final class 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 void
resolveLayoutDirection(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)

This will be called by requestLayout.

static void
setLayoutDirection(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)

Set the layout direction.

static void

Set the relative end margin.

static void

Set the relative start margin.

Public methods

getLayoutDirection

Added in 1.1.0
public static int getLayoutDirection(@NonNull ViewGroup.MarginLayoutParams lp)

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

Returns
int

the layout direction.

getMarginEnd

Added in 1.1.0
public static int getMarginEnd(@NonNull ViewGroup.MarginLayoutParams lp)

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
@NonNull ViewGroup.MarginLayoutParams lp

LayoutParams to query

Returns
int

the margin along the ending edge in pixels

getMarginStart

Added in 1.1.0
public static int getMarginStart(@NonNull ViewGroup.MarginLayoutParams lp)

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
@NonNull ViewGroup.MarginLayoutParams lp

LayoutParams to query

Returns
int

the margin along the starting edge in pixels

isMarginRelative

Added in 1.1.0
public static boolean isMarginRelative(@NonNull ViewGroup.MarginLayoutParams lp)

Check if margins are relative.

Returns
boolean

true if either marginStart or marginEnd has been set.

resolveLayoutDirection

Added in 1.1.0
public static void resolveLayoutDirection(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)

This will be called by requestLayout. Left and Right margins may be overridden depending on layout direction.

setLayoutDirection

Added in 1.1.0
public static void setLayoutDirection(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)

Set the layout direction.

Parameters
@NonNull ViewGroup.MarginLayoutParams lp

LayoutParameters for which to set the layout direction.

int layoutDirection

the layout direction. Should be either LAYOUT_DIRECTION_LTR or LAYOUT_DIRECTION_RTL.

setMarginEnd

Added in 1.1.0
public static void setMarginEnd(@NonNull ViewGroup.MarginLayoutParams lp, int marginEnd)

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
@NonNull ViewGroup.MarginLayoutParams lp

LayoutParams to query

int marginEnd

the desired end margin in pixels

setMarginStart

Added in 1.1.0
public static void setMarginStart(@NonNull ViewGroup.MarginLayoutParams lp, int marginStart)

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
@NonNull ViewGroup.MarginLayoutParams lp

LayoutParams to query

int marginStart

the desired start margin in pixels