Skip to content

Most visited

Recently visited

navigation

GravityCompat

public final class GravityCompat
extends Object

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


Compatibility shim for accessing newer functionality from Gravity.

Summary

Constants

int END

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

int RELATIVE_HORIZONTAL_GRAVITY_MASK

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

int RELATIVE_LAYOUT_DIRECTION

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

int START

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

Public methods

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.

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.

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.

static int getAbsoluteGravity(int gravity, int layoutDirection)

Convert script specific gravity to absolute horizontal value.

Inherited methods

From class java.lang.Object

Constants

END

int END

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

Constant Value: 8388613 (0x00800005)

RELATIVE_HORIZONTAL_GRAVITY_MASK

int RELATIVE_HORIZONTAL_GRAVITY_MASK

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

Constant Value: 8388615 (0x00800007)

RELATIVE_LAYOUT_DIRECTION

int RELATIVE_LAYOUT_DIRECTION

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

Constant Value: 8388608 (0x00800000)

START

int START

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

Constant Value: 8388611 (0x00800003)

Public methods

apply

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.

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.

See also:

apply

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.

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.

See also:

applyDisplay

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) 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.

See also:

getAbsoluteGravity

int getAbsoluteGravity (int gravity, 
                int layoutDirection)

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.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.