# MarginLayoutParamsCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/view/MarginLayoutParamsCompat.java+class:androidx.core.view.MarginLayoutParamsCompat) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

*** ** * ** ***


```
public final class MarginLayoutParamsCompat
```

<br />

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html` directly.

Helper for accessing API features in `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html` in a backwards compatible way.

## Summary

| ### Public methods |
|---|---|
| `static int` | `[getLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getLayoutDirection(android.view.ViewGroup.MarginLayoutParams))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getLayoutDirection()` directly. <br /> |
| `static int` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.getMarginEnd()") [getMarginEnd](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getMarginEnd(android.view.ViewGroup.MarginLayoutParams))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()` directly. <br /> |
| `static int` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.getMarginStart()") [getMarginStart](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getMarginStart(android.view.ViewGroup.MarginLayoutParams))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()` directly. <br /> |
| `static boolean` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.isMarginRelative()") [isMarginRelative](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#isMarginRelative(android.view.ViewGroup.MarginLayoutParams))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#isMarginRelative()` directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.resolveLayoutDirection(layoutDirection)") [resolveLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#resolveLayoutDirection(android.view.ViewGroup.MarginLayoutParams,int))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp, int layoutDirection )` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#resolveLayoutDirection(int)` directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.setLayoutDirection(layoutDirection)") [setLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setLayoutDirection(android.view.ViewGroup.MarginLayoutParams,int))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp, int layoutDirection )` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setLayoutDirection(int)` directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.setMarginEnd(marginEnd)") [setMarginEnd](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setMarginEnd(android.view.ViewGroup.MarginLayoutParams,int))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp, int marginEnd)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginEnd(int)` directly. <br /> |
| `static void` | `@https://developer.android.com/reference/androidx/annotation/ReplaceWith(expression = "lp.setMarginStart(marginStart)") [setMarginStart](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setMarginStart(android.view.ViewGroup.MarginLayoutParams,int))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp, int marginStart)` **This method is deprecated.** Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginStart(int)` directly. <br /> |

## Public methods

### getLayoutDirection

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
public static int [getLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getLayoutDirection(android.view.ViewGroup.MarginLayoutParams))(@NonNull ViewGroup.MarginLayoutParams lp)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getLayoutDirection()` directly.

Returns the layout direction. Can be either `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_LTR()` or `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_RTL()`.

| Returns |
|---|---|
| `int` | the layout direction. |

### getMarginEnd

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.getMarginEnd()")
public static int [getMarginEnd](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getMarginEnd(android.view.ViewGroup.MarginLayoutParams))(@NonNull ViewGroup.MarginLayoutParams lp)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()` directly.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp` | LayoutParams to query |

| Returns |
|---|---|
| `int` | the margin along the ending edge in pixels |

### getMarginStart

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.getMarginStart()")
public static int [getMarginStart](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#getMarginStart(android.view.ViewGroup.MarginLayoutParams))(@NonNull ViewGroup.MarginLayoutParams lp)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#getMarginStart()` directly.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp` | LayoutParams to query |

| Returns |
|---|---|
| `int` | the margin along the starting edge in pixels |

### isMarginRelative

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.isMarginRelative()")
public static boolean [isMarginRelative](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#isMarginRelative(android.view.ViewGroup.MarginLayoutParams))(@NonNull ViewGroup.MarginLayoutParams lp)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#isMarginRelative()` directly.

Check if margins are relative.

| Returns |
|---|---|
| `boolean` | true if either marginStart or marginEnd has been set. |

### resolveLayoutDirection

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.resolveLayoutDirection(layoutDirection)")
public static void [resolveLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#resolveLayoutDirection(android.view.ViewGroup.MarginLayoutParams,int))(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#resolveLayoutDirection(int)` directly.

This will be called by `https://developer.android.com/reference/android/view/View.html#requestLayout()`. Left and Right margins may be overridden depending on layout direction.

### setLayoutDirection

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.setLayoutDirection(layoutDirection)")
public static void [setLayoutDirection](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setLayoutDirection(android.view.ViewGroup.MarginLayoutParams,int))(
    @NonNull ViewGroup.MarginLayoutParams lp,
    int layoutDirection
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setLayoutDirection(int)` directly.

Set the layout direction.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp` | LayoutParameters for which to set the layout direction. |
| `int layoutDirection` | the layout direction. Should be either `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_LTR()` or `https://developer.android.com/reference/androidx/core/view/ViewCompat#LAYOUT_DIRECTION_RTL()`. |

### setMarginEnd

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.setMarginEnd(marginEnd)")
public static void [setMarginEnd](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setMarginEnd(android.view.ViewGroup.MarginLayoutParams,int))(@NonNull ViewGroup.MarginLayoutParams lp, int marginEnd)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginEnd(int)` directly.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp` | LayoutParams to query |
| `int marginEnd` | the desired end margin in pixels |

### setMarginStart

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0) Deprecated in [1.13.0](https://developer.android.com/jetpack/androidx/releases/core#1.13.0)

```
@ReplaceWith(expression = "lp.setMarginStart(marginStart)")
public static void [setMarginStart](https://developer.android.com/reference/androidx/core/view/MarginLayoutParamsCompat#setMarginStart(android.view.ViewGroup.MarginLayoutParams,int))(@NonNull ViewGroup.MarginLayoutParams lp, int marginStart)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html#setMarginStart(int)` directly.

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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html lp` | LayoutParams to query |
| `int marginStart` | the desired start margin in pixels |