# MarginLayoutParamsCompat

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  
belongs to Maven artifact com.android.support:support-compat:28.0.0-alpha1  
Summary:[Methods](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#)  

# MarginLayoutParamsCompat

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
MarginLayoutParamsCompat
`  
`

extends Object


``


`

|---|--------------------------------------------------|
| java.lang.Object                                    ||
| ↳ | android.support.v4.view.MarginLayoutParamsCompat |

<br />

*** ** * ** ***

Helper for accessing API features in[MarginLayoutParams](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/android/support/v4/view/MarginLayoutParamsCompat#getLayoutDirection(android.view.ViewGroup.MarginLayoutParams))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp) ` Returns the layout direction.                                                                                                                              |
| ` static int`     | ` `[getMarginEnd](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#getMarginEnd(android.view.ViewGroup.MarginLayoutParams))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp) ` Get the relative ending margin that was set.                                                                                                                           |
| ` static int`     | ` `[getMarginStart](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#getMarginStart(android.view.ViewGroup.MarginLayoutParams))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp) ` Get the relative starting margin that was set.                                                                                                                     |
| ` static boolean` | ` `[isMarginRelative](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#isMarginRelative(android.view.ViewGroup.MarginLayoutParams))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp) ` Check if margins are relative.                                                                                                                                 |
| ` static void`    | ` `[resolveLayoutDirection](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#resolveLayoutDirection(android.view.ViewGroup.MarginLayoutParams, int))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp, int layoutDirection) ` This will be called by[requestLayout()](https://developer.android.com/reference/android/view/View.html#requestLayout()). |
| ` static void`    | ` `[setLayoutDirection](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#setLayoutDirection(android.view.ViewGroup.MarginLayoutParams, int))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp, int layoutDirection) ` Set the layout direction.                                                                                                        |
| ` static void`    | ` `[setMarginEnd](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#setMarginEnd(android.view.ViewGroup.MarginLayoutParams, int))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp, int marginEnd) ` Set the relative end margin.                                                                                                                       |
| ` static void`    | ` `[setMarginStart](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#setMarginStart(android.view.ViewGroup.MarginLayoutParams, int))`(`[ViewGroup.MarginLayoutParams](https://developer.android.com/reference/android/view/ViewGroup.MarginLayoutParams.html)` lp, int marginStart) ` Set the relative start margin.                                                                                                               |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat#)From class` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public methods

### getLayoutDirection

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getLayoutDirection (ViewGroup.MarginLayoutParams lp)
```

Returns the layout direction. Can be either[LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_LTR)or[LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_RTL).

<br />

|                 Parameters                  ||
|------|---------------------------------------|
| `lp` | `ViewGroup.MarginLayoutParams` <br /> |

|               Returns               ||
|-------|------------------------------|
| `int` | the layout direction. <br /> |

### getMarginEnd

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getMarginEnd (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.

<br />

<br />

|                             Parameters                             ||
|------|--------------------------------------------------------------|
| `lp` | `ViewGroup.MarginLayoutParams`: LayoutParams to query <br /> |

|                         Returns                          ||
|-------|---------------------------------------------------|
| `int` | the margin along the ending edge in pixels <br /> |

### getMarginStart

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
int getMarginStart (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.

<br />

<br />

|                             Parameters                             ||
|------|--------------------------------------------------------------|
| `lp` | `ViewGroup.MarginLayoutParams`: LayoutParams to query <br /> |

|                          Returns                           ||
|-------|-----------------------------------------------------|
| `int` | the margin along the starting edge in pixels <br /> |

### isMarginRelative

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean isMarginRelative (ViewGroup.MarginLayoutParams lp)
```

Check if margins are relative.

<br />

|                 Parameters                  ||
|------|---------------------------------------|
| `lp` | `ViewGroup.MarginLayoutParams` <br /> |

|                                 Returns                                 ||
|-----------|--------------------------------------------------------------|
| `boolean` | true if either marginStart or marginEnd has been set. <br /> |

### resolveLayoutDirection

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void resolveLayoutDirection (ViewGroup.MarginLayoutParams lp, 
                int layoutDirection)
```

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

<br />

|                        Parameters                        ||
|-------------------|---------------------------------------|
| `lp`              | `ViewGroup.MarginLayoutParams` <br /> |
| `layoutDirection` | `int` <br />                          |

### setLayoutDirection

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setLayoutDirection (ViewGroup.MarginLayoutParams lp, 
                int layoutDirection)
```

Set the layout direction.

<br />

|                                                                                                                                                        Parameters                                                                                                                                                        ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `lp`              | `ViewGroup.MarginLayoutParams` <br />                                                                                                                                                                                                                                                                 |
| `layoutDirection` | `int`: the layout direction. Should be either[LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_LTR)or[LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_RTL). <br /> |

### setMarginEnd

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setMarginEnd (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.

<br />

<br />

|                                Parameters                                 ||
|-------------|--------------------------------------------------------------|
| `lp`        | `ViewGroup.MarginLayoutParams`: LayoutParams to query <br /> |
| `marginEnd` | `int`: the desired end margin in pixels <br />               |

### setMarginStart

added in[version 22.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
void setMarginStart (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.

<br />

<br />

|                                 Parameters                                  ||
|---------------|--------------------------------------------------------------|
| `lp`          | `ViewGroup.MarginLayoutParams`: LayoutParams to query <br /> |
| `marginStart` | `int`: the desired start margin in pixels <br />             |

-

  ## Annotations

  - [ViewPager.DecorView](https://developer.android.com/reference/android/support/v4/view/ViewPager.DecorView)
-

  ## Interfaces

  - [ActionProvider.VisibilityListener](https://developer.android.com/reference/android/support/v4/view/ActionProvider.VisibilityListener)
  - [AsyncLayoutInflater.OnInflateFinishedListener](https://developer.android.com/reference/android/support/v4/view/AsyncLayoutInflater.OnInflateFinishedListener)
  - [LayoutInflaterFactory](https://developer.android.com/reference/android/support/v4/view/LayoutInflaterFactory)
  - [MenuItemCompat.OnActionExpandListener](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat.OnActionExpandListener)
  - [NestedScrollingChild](https://developer.android.com/reference/android/support/v4/view/NestedScrollingChild)
  - [NestedScrollingChild2](https://developer.android.com/reference/android/support/v4/view/NestedScrollingChild2)
  - [NestedScrollingParent](https://developer.android.com/reference/android/support/v4/view/NestedScrollingParent)
  - [NestedScrollingParent2](https://developer.android.com/reference/android/support/v4/view/NestedScrollingParent2)
  - [OnApplyWindowInsetsListener](https://developer.android.com/reference/android/support/v4/view/OnApplyWindowInsetsListener)
  - [ScrollingView](https://developer.android.com/reference/android/support/v4/view/ScrollingView)
  - [TintableBackgroundView](https://developer.android.com/reference/android/support/v4/view/TintableBackgroundView)
  - [ViewPager.OnAdapterChangeListener](https://developer.android.com/reference/android/support/v4/view/ViewPager.OnAdapterChangeListener)
  - [ViewPager.OnPageChangeListener](https://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener)
  - [ViewPager.PageTransformer](https://developer.android.com/reference/android/support/v4/view/ViewPager.PageTransformer)
  - [ViewPropertyAnimatorListener](https://developer.android.com/reference/android/support/v4/view/ViewPropertyAnimatorListener)
  - [ViewPropertyAnimatorUpdateListener](https://developer.android.com/reference/android/support/v4/view/ViewPropertyAnimatorUpdateListener)
-

  ## Classes

  - [AbsSavedState](https://developer.android.com/reference/android/support/v4/view/AbsSavedState)
  - [AccessibilityDelegateCompat](https://developer.android.com/reference/android/support/v4/view/AccessibilityDelegateCompat)
  - [ActionProvider](https://developer.android.com/reference/android/support/v4/view/ActionProvider)
  - [AsyncLayoutInflater](https://developer.android.com/reference/android/support/v4/view/AsyncLayoutInflater)
  - [GestureDetectorCompat](https://developer.android.com/reference/android/support/v4/view/GestureDetectorCompat)
  - [GravityCompat](https://developer.android.com/reference/android/support/v4/view/GravityCompat)
  - [InputDeviceCompat](https://developer.android.com/reference/android/support/v4/view/InputDeviceCompat)
  - [LayoutInflaterCompat](https://developer.android.com/reference/android/support/v4/view/LayoutInflaterCompat)
  - [MarginLayoutParamsCompat](https://developer.android.com/reference/android/support/v4/view/MarginLayoutParamsCompat)
  - [MenuCompat](https://developer.android.com/reference/android/support/v4/view/MenuCompat)
  - [MenuItemCompat](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat)
  - [MotionEventCompat](https://developer.android.com/reference/android/support/v4/view/MotionEventCompat)
  - [NestedScrollingChildHelper](https://developer.android.com/reference/android/support/v4/view/NestedScrollingChildHelper)
  - [NestedScrollingParentHelper](https://developer.android.com/reference/android/support/v4/view/NestedScrollingParentHelper)
  - [PagerAdapter](https://developer.android.com/reference/android/support/v4/view/PagerAdapter)
  - [PagerTabStrip](https://developer.android.com/reference/android/support/v4/view/PagerTabStrip)
  - [PagerTitleStrip](https://developer.android.com/reference/android/support/v4/view/PagerTitleStrip)
  - [PointerIconCompat](https://developer.android.com/reference/android/support/v4/view/PointerIconCompat)
  - [ScaleGestureDetectorCompat](https://developer.android.com/reference/android/support/v4/view/ScaleGestureDetectorCompat)
  - [VelocityTrackerCompat](https://developer.android.com/reference/android/support/v4/view/VelocityTrackerCompat)
  - [ViewCompat](https://developer.android.com/reference/android/support/v4/view/ViewCompat)
  - [ViewConfigurationCompat](https://developer.android.com/reference/android/support/v4/view/ViewConfigurationCompat)
  - [ViewGroupCompat](https://developer.android.com/reference/android/support/v4/view/ViewGroupCompat)
  - [ViewPager](https://developer.android.com/reference/android/support/v4/view/ViewPager)
  - [ViewPager.LayoutParams](https://developer.android.com/reference/android/support/v4/view/ViewPager.LayoutParams)
  - [ViewPager.SavedState](https://developer.android.com/reference/android/support/v4/view/ViewPager.SavedState)
  - [ViewPager.SimpleOnPageChangeListener](https://developer.android.com/reference/android/support/v4/view/ViewPager.SimpleOnPageChangeListener)
  - [ViewParentCompat](https://developer.android.com/reference/android/support/v4/view/ViewParentCompat)
  - [ViewPropertyAnimatorCompat](https://developer.android.com/reference/android/support/v4/view/ViewPropertyAnimatorCompat)
  - [ViewPropertyAnimatorListenerAdapter](https://developer.android.com/reference/android/support/v4/view/ViewPropertyAnimatorListenerAdapter)
  - [WindowCompat](https://developer.android.com/reference/android/support/v4/view/WindowCompat)
  - [WindowInsetsCompat](https://developer.android.com/reference/android/support/v4/view/WindowInsetsCompat)