# GravityCompat

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:[Constants](https://developer.android.com/reference/android/support/v4/view/GravityCompat#constants)\|[Methods](https://developer.android.com/reference/android/support/v4/view/GravityCompat#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v4/view/GravityCompat#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v4/view/GravityCompat#)  

# GravityCompat

| 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
GravityCompat
`  
`

extends Object


``


`

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

<br />

*** ** * ** ***

Compatibility shim for accessing newer functionality from[Gravity](https://developer.android.com/reference/android/view/Gravity.html).

## Summary

|                                                                                                                        ### Constants                                                                                                                        ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [END](https://developer.android.com/reference/android/support/v4/view/GravityCompat#END) Push object to x-axis position at the end of its container, not changing its size.                                                                          |
| `int` | [RELATIVE_HORIZONTAL_GRAVITY_MASK](https://developer.android.com/reference/android/support/v4/view/GravityCompat#RELATIVE_HORIZONTAL_GRAVITY_MASK) Binary mask for the horizontal gravity and script specific direction bit.                         |
| `int` | [RELATIVE_LAYOUT_DIRECTION](https://developer.android.com/reference/android/support/v4/view/GravityCompat#RELATIVE_LAYOUT_DIRECTION) Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT). |
| `int` | [START](https://developer.android.com/reference/android/support/v4/view/GravityCompat#START) Push object to x-axis position at the start of its container, not changing its size.                                                                    |

|                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                             ||
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void` | ` `[apply](https://developer.android.com/reference/android/support/v4/view/GravityCompat#apply(int, int, int, android.graphics.Rect, android.graphics.Rect, int))`(int gravity, int w, int h, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` container, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` outRect, int layoutDirection) ` Apply a gravity constant to an object and take care if layout direction is RTL or not. |
| ` static void` | ` `[apply](https://developer.android.com/reference/android/support/v4/view/GravityCompat#apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect, int))`(int gravity, int w, int h, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` container, int xAdj, int yAdj, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` outRect, int layoutDirection) ` Apply a gravity constant to an object.                   |
| ` static void` | ` `[applyDisplay](https://developer.android.com/reference/android/support/v4/view/GravityCompat#applyDisplay(int, android.graphics.Rect, android.graphics.Rect, int))`(int gravity, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` display, `[Rect](https://developer.android.com/reference/android/graphics/Rect.html)` inoutObj, int layoutDirection) ` Apply additional gravity behavior based on the overall "display" that an object exists in.        |
| ` static int`  | ` `[getAbsoluteGravity](https://developer.android.com/reference/android/support/v4/view/GravityCompat#getAbsoluteGravity(int, int))`(int gravity, int layoutDirection) ` <br /> Convert script specific gravity to absolute horizontal value.                                                                                                                                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4/view/GravityCompat#)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() `                    | ||

## Constants

### END

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

```
int END
```

Push object to x-axis position at the end of its container, not changing its size.

<br />

Constant Value: 8388613 (0x00800005)  

### RELATIVE_HORIZONTAL_GRAVITY_MASK

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

```
int RELATIVE_HORIZONTAL_GRAVITY_MASK
```

Binary mask for the horizontal gravity and script specific direction bit.

<br />

Constant Value: 8388615 (0x00800007)  

### RELATIVE_LAYOUT_DIRECTION

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

```
int RELATIVE_LAYOUT_DIRECTION
```

Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT).

<br />

Constant Value: 8388608 (0x00800000)  

### START

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

```
int START
```

Push object to x-axis position at the start of its container, not changing its size.

<br />

Constant Value: 8388611 (0x00800003)

## Public methods

### apply

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

```
void apply (int gravity, 
                int w, 
                int h, 
                Rect container, 
                Rect outRect, 
                int layoutDirection)
```

Apply a gravity constant to an object and take care if layout direction is RTL or not.

<br />

|                                                                                   Parameters                                                                                   ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `gravity`         | `int`: The desired placement of the object, as defined by the constants in this class. <br />                                                               |
| `w`               | `int`: The horizontal size of the object. <br />                                                                                                            |
| `h`               | `int`: The vertical size of the object. <br />                                                                                                              |
| `container`       | `Rect`: The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object. <br /> |
| `outRect`         | `Rect`: Receives the computed frame of the object in its container. <br />                                                                                  |
| `layoutDirection` | `int`: The layout direction. <br />                                                                                                                         |

**See also:**

- [LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_LTR)
- [LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_RTL)  

### apply

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

```
void apply (int gravity, 
                int w, 
                int h, 
                Rect container, 
                int xAdj, 
                int yAdj, 
                Rect outRect, 
                int layoutDirection)
```

Apply a gravity constant to an object.

<br />

|                                                                                                                        Parameters                                                                                                                         ||
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `gravity`         | `int`: The desired placement of the object, as defined by the constants in this class. <br />                                                                                                                                          |
| `w`               | `int`: The horizontal size of the object. <br />                                                                                                                                                                                       |
| `h`               | `int`: The vertical size of the object. <br />                                                                                                                                                                                         |
| `container`       | `Rect`: The frame of the containing space, in which the object will be placed. Should be large enough to contain the width and height of the object. <br />                                                                            |
| `xAdj`            | `int`: Offset to apply to the X axis. If gravity is LEFT this pushes it to the right; if gravity is RIGHT it pushes it to the left; if gravity is CENTER_HORIZONTAL it pushes it to the right or left; otherwise it is ignored. <br /> |
| `yAdj`            | `int`: Offset to apply to the Y axis. If gravity is TOP this pushes it down; if gravity is BOTTOM it pushes it up; if gravity is CENTER_VERTICAL it pushes it down or up; otherwise it is ignored. <br />                              |
| `outRect`         | `Rect`: Receives the computed frame of the object in its container. <br />                                                                                                                                                             |
| `layoutDirection` | `int`: The layout direction. <br />                                                                                                                                                                                                    |

**See also:**

- [LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_LTR)
- [LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_RTL)  

### applyDisplay

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

```
void applyDisplay (int gravity, 
                Rect display, 
                Rect inoutObj, 
                int layoutDirection)
```

Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after[apply(int, int, int, Rect, int, int, Rect)](https://developer.android.com/reference/android/view/Gravity.html#apply(int, int, int, android.graphics.Rect, int, int, android.graphics.Rect))to place the object within a visible display. By default this moves or clips the object to be visible in the display; the gravity flags[DISPLAY_CLIP_HORIZONTAL](https://developer.android.com/reference/android/view/Gravity.html#DISPLAY_CLIP_HORIZONTAL)and[DISPLAY_CLIP_VERTICAL](https://developer.android.com/reference/android/view/Gravity.html#DISPLAY_CLIP_VERTICAL)can be used to change this behavior.

<br />

|                                                            Parameters                                                             ||
|-------------------|----------------------------------------------------------------------------------------------------------------|
| `gravity`         | `int`: Gravity constants to modify the placement within the display. <br />                                    |
| `display`         | `Rect`: The rectangle of the display in which the object is being placed. <br />                               |
| `inoutObj`        | `Rect`: Supplies the current object position; returns with it modified if needed to fit in the display. <br /> |
| `layoutDirection` | `int`: The layout direction. <br />                                                                            |

**See also:**

- [LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_LTR)
- [LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/support/v4/view/ViewCompat#LAYOUT_DIRECTION_RTL)  

### getAbsoluteGravity

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

```
int getAbsoluteGravity (int gravity, 
                int layoutDirection)
```

<br />

Convert script specific gravity to absolute horizontal value.
if horizontal direction is LTR, then START will set LEFT and END will set RIGHT. if horizontal direction is RTL, then START will set RIGHT and END will set LEFT.

<br />

<br />

|                                        Parameters                                        ||
|-------------------|-----------------------------------------------------------------------|
| `gravity`         | `int`: The gravity to convert to absolute (horizontal) values. <br /> |
| `layoutDirection` | `int`: The layout direction. <br />                                   |

|                             Returns                              ||
|-------|-----------------------------------------------------------|
| `int` | gravity converted to absolute (horizontal) values. <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)