GravityCompat

Added in 1.1.0

class GravityCompat


Compatibility shim for accessing newer functionality from Gravity.

Summary

Constants

const Int
END = 8388613

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

const Int

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

const Int

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

const Int
START = 8388611

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

Public functions

java-static Unit
apply(
    gravity: Int,
    w: Int,
    h: Int,
    container: Rect,
    outRect: Rect,
    layoutDirection: Int
)

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

java-static Unit
apply(
    gravity: Int,
    w: Int,
    h: Int,
    container: Rect,
    xAdj: Int,
    yAdj: Int,
    outRect: Rect,
    layoutDirection: Int
)

Apply a gravity constant to an object.

java-static Unit
applyDisplay(
    gravity: Int,
    display: Rect,
    inoutObj: Rect,
    layoutDirection: Int
)

Apply additional gravity behavior based on the overall "display" that an object exists in.

java-static Int
getAbsoluteGravity(gravity: Int, layoutDirection: Int)

Convert script specific gravity to absolute horizontal value.

Constants

END

Added in 1.1.0
const val END = 8388613: Int

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

RELATIVE_HORIZONTAL_GRAVITY_MASK

Added in 1.1.0
const val RELATIVE_HORIZONTAL_GRAVITY_MASK = 8388615: Int

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

RELATIVE_LAYOUT_DIRECTION

Added in 1.1.0
const val RELATIVE_LAYOUT_DIRECTION = 8388608: Int

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

START

Added in 1.1.0
const val START = 8388611: Int

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

Public functions

apply

Added in 1.1.0
java-static fun apply(
    gravity: Int,
    w: Int,
    h: Int,
    container: Rect,
    outRect: Rect,
    layoutDirection: Int
): Unit

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

Parameters
gravity: Int

The desired placement of the object, as defined by the constants in this class.

w: Int

The horizontal size of the object.

h: Int

The vertical size of the object.

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.

outRect: Rect

Receives the computed frame of the object in its container.

layoutDirection: Int

The layout direction.

apply

Added in 1.1.0
java-static fun apply(
    gravity: Int,
    w: Int,
    h: Int,
    container: Rect,
    xAdj: Int,
    yAdj: Int,
    outRect: Rect,
    layoutDirection: Int
): Unit

Apply a gravity constant to an object.

Parameters
gravity: Int

The desired placement of the object, as defined by the constants in this class.

w: Int

The horizontal size of the object.

h: Int

The vertical size of the object.

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.

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.

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.

outRect: Rect

Receives the computed frame of the object in its container.

layoutDirection: Int

The layout direction.

applyDisplay

Added in 1.1.0
java-static fun applyDisplay(
    gravity: Int,
    display: Rect,
    inoutObj: Rect,
    layoutDirection: Int
): Unit

Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after apply 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 and DISPLAY_CLIP_VERTICAL can be used to change this behavior.

Parameters
gravity: Int

Gravity constants to modify the placement within the display.

display: Rect

The rectangle of the display in which the object is being placed.

inoutObj: Rect

Supplies the current object position; returns with it modified if needed to fit in the display.

layoutDirection: Int

The layout direction.

getAbsoluteGravity

Added in 1.1.0
java-static fun getAbsoluteGravity(gravity: Int, layoutDirection: Int): Int

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.
Parameters
gravity: Int

The gravity to convert to absolute (horizontal) values.

layoutDirection: Int

The layout direction.

Returns
Int

gravity converted to absolute (horizontal) values.