android.support.v4.view
Class GravityCompat

java.lang.Object
  extended by android.support.v4.view.GravityCompat

public class GravityCompat
extends Object

Compatibility shim for accessing newer functionality from Gravity.


Field Summary
static int END
          Push object to x-axis position at the end of its container, not changing its size.
static int RELATIVE_HORIZONTAL_GRAVITY_MASK
          Binary mask for the horizontal gravity and script specific direction bit.
static int RELATIVE_LAYOUT_DIRECTION
          Raw bit controlling whether the layout direction is relative or not (START/END instead of absolute LEFT/RIGHT).
static int START
          Push object to x-axis position at the start of its container, not changing its size.
 
Constructor Summary
GravityCompat()
           
 
Method Summary
static void apply(int gravity, int w, int h, android.graphics.Rect container, int xAdj, int yAdj, android.graphics.Rect outRect, int layoutDirection)
          Apply a gravity constant to an object.
static void apply(int gravity, int w, int h, android.graphics.Rect container, 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 applyDisplay(int gravity, android.graphics.Rect display, android.graphics.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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RELATIVE_LAYOUT_DIRECTION

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

See Also:
Constant Field Values

START

public static final int START
Push object to x-axis position at the start of its container, not changing its size.

See Also:
Constant Field Values

END

public static final int END
Push object to x-axis position at the end of its container, not changing its size.

See Also:
Constant Field Values

RELATIVE_HORIZONTAL_GRAVITY_MASK

public static final int RELATIVE_HORIZONTAL_GRAVITY_MASK
Binary mask for the horizontal gravity and script specific direction bit.

See Also:
Constant Field Values
Constructor Detail

GravityCompat

public GravityCompat()
Method Detail

apply

public static void apply(int gravity,
                         int w,
                         int h,
                         android.graphics.Rect container,
                         android.graphics.Rect outRect,
                         int layoutDirection)
Apply a gravity constant to an object and take care if layout direction is RTL or not.

Parameters:
gravity - The desired placement of the object, as defined by the constants in this class.
w - The horizontal size of the object.
h - The vertical size of the object.
container - 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 - Receives the computed frame of the object in its container.
layoutDirection - The layout direction.
See Also:
ViewCompat.LAYOUT_DIRECTION_LTR, ViewCompat.LAYOUT_DIRECTION_RTL

apply

public static void apply(int gravity,
                         int w,
                         int h,
                         android.graphics.Rect container,
                         int xAdj,
                         int yAdj,
                         android.graphics.Rect outRect,
                         int layoutDirection)
Apply a gravity constant to an object.

Parameters:
gravity - The desired placement of the object, as defined by the constants in this class.
w - The horizontal size of the object.
h - The vertical size of the object.
container - 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 - 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 - 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 - Receives the computed frame of the object in its container.
layoutDirection - The layout direction.
See Also:
ViewCompat.LAYOUT_DIRECTION_LTR, ViewCompat.LAYOUT_DIRECTION_RTL

applyDisplay

public static void applyDisplay(int gravity,
                                android.graphics.Rect display,
                                android.graphics.Rect inoutObj,
                                int layoutDirection)
Apply additional gravity behavior based on the overall "display" that an object exists in. This can be used after Gravity.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 Gravity.DISPLAY_CLIP_HORIZONTAL and Gravity.DISPLAY_CLIP_VERTICAL can be used to change this behavior.

Parameters:
gravity - Gravity constants to modify the placement within the display.
display - The rectangle of the display in which the object is being placed.
inoutObj - Supplies the current object position; returns with it modified if needed to fit in the display.
layoutDirection - The layout direction.
See Also:
ViewCompat.LAYOUT_DIRECTION_LTR, ViewCompat.LAYOUT_DIRECTION_RTL

getAbsoluteGravity

public static 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 - The gravity to convert to absolute (horizontal) values.
layoutDirection - The layout direction.
Returns:
gravity converted to absolute (horizontal) values.


Copyright © 2013 Marek Kedzierski. All Rights Reserved.