Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/view/Gravity#constants) \| [Ctors](https://developer.android.com/reference/android/view/Gravity#pubctors) \| [Methods](https://developer.android.com/reference/android/view/Gravity#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/Gravity#inhmethods)

# Gravity

*** ** * ** ***

` public class Gravity `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.Gravity |

<br />

*** ** * ** ***

Standard constants and tools for placing an object within a potentially larger container.

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_CLIP` Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_PULL_AFTER` Raw bit controlling how the right/bottom edge is placed. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_PULL_BEFORE` Raw bit controlling how the left/top edge is placed. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_SPECIFIED` Raw bit indicating the gravity for an axis has been specified. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_X_SHIFT` Bits defining the horizontal axis. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#AXIS_Y_SHIFT` Bits defining the vertical axis. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#BOTTOM` Push object to the bottom of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#CENTER` Place the object in the center of its container in both the vertical and horizontal axis, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#CENTER_HORIZONTAL` Place object in the horizontal center of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#CENTER_VERTICAL` Place object in the vertical center of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#CLIP_HORIZONTAL` Flag to clip the edges of the object to its container along the horizontal axis. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#CLIP_VERTICAL` Flag to clip the edges of the object to its container along the vertical axis. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#DISPLAY_CLIP_HORIZONTAL` Special constant to enable clipping to an overall display along the horizontal dimension. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#DISPLAY_CLIP_VERTICAL` Special constant to enable clipping to an overall display along the vertical dimension. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#END` Push object to x-axis position at the end of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#FILL` Grow the horizontal and vertical size of the object if needed so it completely fills its container. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#FILL_HORIZONTAL` Grow the horizontal size of the object if needed so it completely fills its container. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#FILL_VERTICAL` Grow the vertical size of the object if needed so it completely fills its container. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#HORIZONTAL_GRAVITY_MASK` Binary mask to get the absolute horizontal gravity of a gravity. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#LEFT` Push object to the left of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#NO_GRAVITY` Constant indicating that no gravity has been set \* |
| `int` | `https://developer.android.com/reference/android/view/Gravity#RELATIVE_HORIZONTAL_GRAVITY_MASK` Binary mask for the horizontal gravity and script specific direction bit. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#RELATIVE_LAYOUT_DIRECTION` Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT). |
| `int` | `https://developer.android.com/reference/android/view/Gravity#RIGHT` Push object to the right of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#START` Push object to x-axis position at the start of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#TOP` Push object to the top of its container, not changing its size. |
| `int` | `https://developer.android.com/reference/android/view/Gravity#VERTICAL_GRAVITY_MASK` Binary mask to get the vertical gravity of a gravity. |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/Gravity#Gravity()() ` |

| ### Public methods ||
|---|---|
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.graphics.Rect)(int gravity, int w, int h, https://developer.android.com/reference/android/graphics/Rect container, int xAdj, int yAdj, https://developer.android.com/reference/android/graphics/Rect outRect) ` Apply a gravity constant to an object. |
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20android.graphics.Rect,%20int)(int gravity, int w, int h, https://developer.android.com/reference/android/graphics/Rect container, https://developer.android.com/reference/android/graphics/Rect outRect, int layoutDirection) ` Apply a gravity constant to an object and take care if layout direction is RTL or not. |
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.graphics.Rect,%20int)(int gravity, int w, int h, https://developer.android.com/reference/android/graphics/Rect container, int xAdj, int yAdj, https://developer.android.com/reference/android/graphics/Rect outRect, int layoutDirection) ` Apply a gravity constant to an object. |
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20android.graphics.Rect)(int gravity, int w, int h, https://developer.android.com/reference/android/graphics/Rect container, https://developer.android.com/reference/android/graphics/Rect outRect) ` Apply a gravity constant to an object. |
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#applyDisplay(int,%20android.graphics.Rect,%20android.graphics.Rect)(int gravity, https://developer.android.com/reference/android/graphics/Rect display, https://developer.android.com/reference/android/graphics/Rect inoutObj) ` Apply additional gravity behavior based on the overall "display" that an object exists in. |
| ` static void` | ` https://developer.android.com/reference/android/view/Gravity#applyDisplay(int,%20android.graphics.Rect,%20android.graphics.Rect,%20int)(int gravity, https://developer.android.com/reference/android/graphics/Rect display, https://developer.android.com/reference/android/graphics/Rect inoutObj, int layoutDirection) ` Apply additional gravity behavior based on the overall "display" that an object exists in. |
| ` static int` | ` https://developer.android.com/reference/android/view/Gravity#getAbsoluteGravity(int,%20int)(int gravity, int layoutDirection) ` <br /> Convert script specific gravity to absolute horizontal value. |
| ` static boolean` | ` https://developer.android.com/reference/android/view/Gravity#isHorizontal(int)(int gravity) ` <br /> Indicate whether the supplied gravity has an horizontal pull. |
| ` static boolean` | ` https://developer.android.com/reference/android/view/Gravity#isVertical(int)(int gravity) ` <br /> Indicate whether the supplied gravity has a vertical pull. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### AXIS_CLIP

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_CLIP
```

Raw bit controlling whether the right/bottom edge is clipped to its container, based on the gravity direction being applied.

<br />

Constant Value: 8 (0x00000008)

### AXIS_PULL_AFTER

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_PULL_AFTER
```

Raw bit controlling how the right/bottom edge is placed.

<br />

Constant Value: 4 (0x00000004)

### AXIS_PULL_BEFORE

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_PULL_BEFORE
```

Raw bit controlling how the left/top edge is placed.

<br />

Constant Value: 2 (0x00000002)

### AXIS_SPECIFIED

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_SPECIFIED
```

Raw bit indicating the gravity for an axis has been specified.

<br />

Constant Value: 1 (0x00000001)

### AXIS_X_SHIFT

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_X_SHIFT
```

Bits defining the horizontal axis.

<br />

Constant Value: 0 (0x00000000)

### AXIS_Y_SHIFT

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int AXIS_Y_SHIFT
```

Bits defining the vertical axis.

<br />

Constant Value: 4 (0x00000004)

### BOTTOM

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int BOTTOM
```

Push object to the bottom of its container, not changing its size.

<br />

Constant Value: 80 (0x00000050)

### CENTER

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CENTER
```

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

<br />

Constant Value: 17 (0x00000011)

### CENTER_HORIZONTAL

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CENTER_HORIZONTAL
```

Place object in the horizontal center of its container, not changing its size.

<br />

Constant Value: 1 (0x00000001)

### CENTER_VERTICAL

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CENTER_VERTICAL
```

Place object in the vertical center of its container, not changing its size.

<br />

Constant Value: 16 (0x00000010)

### CLIP_HORIZONTAL

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CLIP_HORIZONTAL
```

Flag to clip the edges of the object to its container along the horizontal axis.

<br />

Constant Value: 8 (0x00000008)

### CLIP_VERTICAL

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CLIP_VERTICAL
```

Flag to clip the edges of the object to its container along the vertical axis.

<br />

Constant Value: 128 (0x00000080)

### DISPLAY_CLIP_HORIZONTAL

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DISPLAY_CLIP_HORIZONTAL
```

Special constant to enable clipping to an overall display along the horizontal dimension. This is not applied by default by `https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.graphics.Rect)`; you must do so yourself by calling `https://developer.android.com/reference/android/view/Gravity#applyDisplay(int,%20android.graphics.Rect,%20android.graphics.Rect)`.

<br />

Constant Value: 16777216 (0x01000000)

### DISPLAY_CLIP_VERTICAL

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int DISPLAY_CLIP_VERTICAL
```

Special constant to enable clipping to an overall display along the vertical dimension. This is not applied by default by `https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.graphics.Rect)`; you must do so yourself by calling `https://developer.android.com/reference/android/view/Gravity#applyDisplay(int,%20android.graphics.Rect,%20android.graphics.Rect)`.

<br />

Constant Value: 268435456 (0x10000000)

### END

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int END
```

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

<br />

Constant Value: 8388613 (0x00800005)

### FILL

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FILL
```

Grow the horizontal and vertical size of the object if needed so it completely fills its container.

<br />

Constant Value: 119 (0x00000077)

### FILL_HORIZONTAL

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FILL_HORIZONTAL
```

Grow the horizontal size of the object if needed so it completely fills its container.

<br />

Constant Value: 7 (0x00000007)

### FILL_VERTICAL

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FILL_VERTICAL
```

Grow the vertical size of the object if needed so it completely fills its container.

<br />

Constant Value: 112 (0x00000070)

### HORIZONTAL_GRAVITY_MASK

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int HORIZONTAL_GRAVITY_MASK
```

Binary mask to get the absolute horizontal gravity of a gravity.

<br />

Constant Value: 7 (0x00000007)

### LEFT

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int LEFT
```

Push object to the left of its container, not changing its size.

<br />

Constant Value: 3 (0x00000003)

### NO_GRAVITY

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int NO_GRAVITY
```

Constant indicating that no gravity has been set \*

<br />

Constant Value: 0 (0x00000000)

### RELATIVE_HORIZONTAL_GRAVITY_MASK

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final 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 [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final 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)

### RIGHT

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int RIGHT
```

Push object to the right of its container, not changing its size.

<br />

Constant Value: 5 (0x00000005)

### START

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int START
```

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

<br />

Constant Value: 8388611 (0x00800003)

### TOP

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int TOP
```

Push object to the top of its container, not changing its size.

<br />

Constant Value: 48 (0x00000030)

### VERTICAL_GRAVITY_MASK

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int VERTICAL_GRAVITY_MASK
```

Binary mask to get the vertical gravity of a gravity.

<br />

Constant Value: 112 (0x00000070)

## Public constructors

### Gravity

```
public Gravity ()
```

<br />

<br />

## Public methods

### apply

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

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. This value cannot be `null`. <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. This value cannot be `null`. <br /> |

### apply

Added in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static 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. This value cannot be `null`. <br /> |
| `outRect` | `Rect`: Receives the computed frame of the object in its container. This value cannot be `null`. <br /> |
| `layoutDirection` | `int`: The layout direction. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_LTR`
- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_RTL`

### apply

Added in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static 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. This value cannot be `null`. <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. This value cannot be `null`. <br /> |
| `layoutDirection` | `int`: The layout direction. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_LTR`
- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_RTL`

### apply

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

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

Apply a gravity constant to an object. This supposes that the layout direction is LTR.

<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 /> |

### applyDisplay

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static void applyDisplay (int gravity, 
                Rect display, 
                Rect inoutObj)
```

Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after `https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.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 `https://developer.android.com/reference/android/view/Gravity#DISPLAY_CLIP_HORIZONTAL` and `https://developer.android.com/reference/android/view/Gravity#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. This value cannot be `null`. <br /> |
| `inoutObj` | `Rect`: Supplies the current object position; returns with it modified if needed to fit in the display. This value cannot be `null`. <br /> |

### applyDisplay

Added in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static 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 `https://developer.android.com/reference/android/view/Gravity#apply(int,%20int,%20int,%20android.graphics.Rect,%20int,%20int,%20android.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 `https://developer.android.com/reference/android/view/Gravity#DISPLAY_CLIP_HORIZONTAL` and `https://developer.android.com/reference/android/view/Gravity#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. This value cannot be `null`. <br /> |
| `inoutObj` | `Rect`: Supplies the current object position; returns with it modified if needed to fit in the display. This value cannot be `null`. <br /> |
| `layoutDirection` | `int`: The layout direction. <br /> |

**See also:**

- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_LTR`
- `https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_RTL`

### getAbsoluteGravity

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static 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 /> |

### isHorizontal

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isHorizontal (int gravity)
```

<br />

Indicate whether the supplied gravity has an horizontal pull.

<br />

<br />

| Parameters ||
|---|---|
| `gravity` | `int`: the gravity to check for horizontal pull <br /> |

| Returns ||
|---|---|
| `boolean` | true if the supplied gravity has an horizontal pull <br /> |

### isVertical

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static boolean isVertical (int gravity)
```

<br />

Indicate whether the supplied gravity has a vertical pull.

<br />

<br />

| Parameters ||
|---|---|
| `gravity` | `int`: the gravity to check for vertical pull <br /> |

| Returns ||
|---|---|
| `boolean` | true if the supplied gravity has a vertical pull <br /> |