public class ConstraintWidget

Known direct subclasses
Guideline

Guideline

HelperWidget

HelperWidget class

WidgetContainer

A container of ConstraintWidget

Known indirect subclasses
Barrier

A Barrier takes multiple widgets

ConstraintWidgetContainer

A container of ConstraintWidget that can layout its children

Flow

Implements the Flow virtual layout.

GridCore

The Grid Helper in the Core library that helps to enable Grid in Compose

Placeholder

Simple VirtualLayout that center the first referenced widget onto itself.

VirtualLayout

Base class for Virtual layouts


Implements a constraint Widget model supporting constraints relations between other widgets.

The widget has various anchors (i.e. Left, Top, Right, Bottom, representing their respective sides, as well as Baseline, Center_X and Center_Y). Connecting anchors from one widget to another represents a constraint relation between the two anchors; the LinearSystem will then be able to use this model to try to minimize the distances between connected anchors.

If opposite anchors are connected (e.g. Left and Right anchors), if they have the same strength, the widget will be equally pulled toward their respective target anchor positions; if the widget has a fixed size, this means that the widget will be centered between the two target anchors. If the widget's size is allowed to adjust, the size of the widget will change to be as large as necessary so that the widget's anchors and the target anchors' distances are zero.

Constraints are set by connecting a widget's anchor to another via the connect function.

Summary

Nested types

Define how the widget will resize

Constants

static final int
static final int
static final int
static final int
static final int
static final int
BOTH = 2
static final int
static final int
static final int
static final int
DIRECT = 2
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
SOLVER = 1
static final int
UNKNOWN = -1
static final int
static final int
static final int
static final int
static final int
static final int

Protected fields

ArrayList<ConstraintAnchor>
int
ConstraintWidget[]
int
int
ConstraintWidget[]
int
int
int
int

Public constructors

Default constructor

ConstraintWidget(int width, int height)

Constructor

ConstraintWidget(String debugName, int width, int height)
ConstraintWidget(int x, int y, int width, int height)

Constructor

ConstraintWidget(String debugName, int x, int y, int width, int height)

Public methods

void
addChildrenToSolverByDependency(
    ConstraintWidgetContainer container,
    LinearSystem system,
    HashSet<ConstraintWidget> widgets,
    int orientation,
    boolean addSelf
)
void
addToSolver(LinearSystem system, boolean optimize)

Add this widget to the solver

boolean

Returns true if this widget should be used in a barrier

void
connect(
    ConstraintAnchor.Type constraintFrom,
    ConstraintWidget target,
    ConstraintAnchor.Type constraintTo
)

Connect a given anchor of this widget to another anchor of a target widget

void
connect(ConstraintAnchor from, ConstraintAnchor to, int margin)

Connect the given anchors together (the from anchor should be owned by this widget)

void
connect(
    ConstraintAnchor.Type constraintFrom,
    ConstraintWidget target,
    ConstraintAnchor.Type constraintTo,
    int margin
)

Connect a given anchor of this widget to another anchor of a target widget

void
connectCircularConstraint(
    ConstraintWidget target,
    float angle,
    int radius
)

Set a circular constraint

void
void

Create all the system variables for this widget

void
void
ConstraintAnchor

Given a type of anchor, returns the corresponding anchor.

ArrayList<ConstraintAnchor>

Return the array of anchors of this widget

int

Return the baseline distance relative to the top of the widget

float
getBiasPercent(int orientation)

Return the percentage bias that is used when two opposite connections exist of the same strength in a particular orientation.

int

Return the bottom position of the widget

Object

Return the companion widget.

int

Accessor for the skip value

String

Returns the name of this widget (used for debug purposes)

ConstraintWidget.DimensionBehaviour
getDimensionBehaviour(int orientation)

Get the widget's DimensionBehaviour in an specific orientation.

float

Return the current ratio of this widget

int

Return the current side on which ratio will be applied

boolean
int

Return the height of the widget

float

Return the horizontal percentage bias that is used when two opposite connections exist of the same strength.

ConstraintWidget

if in a horizontal chain return the left most widget in the chain.

int

get the chain starting from this widget to be packed.

ConstraintWidget.DimensionBehaviour

Accessor for the horizontal dimension behaviour

int

Returns all the horizontal margin of the widget.

int
int
int

Return the left position of the widget (similar to getX)

int
getLength(int orientation)

Get a dimension of the widget in a particular orientation.

int
int
int

Return the minimum height of the widget

int

Return the minimum width of the widget

ConstraintWidget
getNextChainMember(int orientation)

Return the next chain member if one exists

int
int
ConstraintWidget

Returns the parent of this widget if there is one

ConstraintWidget
getPreviousChainMember(int orientation)

Return the previous chain member if one exists

int

Return the right position of the widget

WidgetRun
getRun(int orientation)
void
int

Return the top position of the widget (similar to getY)

String

Returns the type string if set

float

Return the vertical percentage bias that is used when two opposite connections exist of the same strength.

ConstraintWidget

if in a vertical chain return the top most widget in the chain.

int

Set the chain starting from this widget to be packed.

ConstraintWidget.DimensionBehaviour

Accessor for the vertical dimension behaviour

int

Returns all the vertical margin of the widget

int

Returns the current visibility value for this widget

int

Return the width of the widget

int
int

Return the x position of the widget, relative to its container

int

Return the y position of the widget, relative to its container

boolean

Return true if this widget has a baseline

boolean
hasDanglingDimension(int orientation)
boolean
boolean
boolean
hasResolvedTargets(int orientation, int size)
void
immediateConnect(
    ConstraintAnchor.Type startType,
    ConstraintWidget target,
    ConstraintAnchor.Type endType,
    int margin,
    int goneMargin
)

Immediate connection to an anchor without any checks.

boolean

Returns if this widget is animated.

boolean

Returns true if height is set to wrap_content

boolean
boolean
isInBarrier(int orientation)
boolean

Test if you are in a Horizontal chain

boolean
boolean

Test if you are in a vertical chain

boolean
boolean
boolean
boolean
boolean

Returns true if the widget is the root widget

boolean
boolean
boolean
boolean

Returns true if width is set to wrap_content

void
void
boolean
oppositeDimensionDependsOn(int orientation)
boolean
void
void

Reset all the constraints set on this widget

void

Reset the given anchor

void

Reset all connections

void
void

Reset the solver variables of the anchors

void
StringBuilder

Serialize the anchors for JSON5 output

void
setAnimated(boolean animated)

Set if this widget is animated.

void
setBaselineDistance(int baseline)

Set the baseline distance relative to the top of the widget

void

Set the companion widget.

void

Set the skip value for this widget.

void

Set the debug name of this widget

void

Utility debug function.

void
setDimension(int w, int h)

Set both width and height of the widget

void

Set the ratio of the widget

void
setDimensionRatio(float ratio, int dimensionRatioSide)

Set the ratio of the widget The ratio will be applied if at least one of the dimension (width or height) is set to a behaviour of DimensionBehaviour.MATCH_CONSTRAINT -- the dimension's value will be set to the other dimension * ratio.

void
setFinalBaseline(int baselineValue)
void
setFinalFrame(
    int left,
    int top,
    int right,
    int bottom,
    int baseline,
    int orientation
)
void
setFinalHorizontal(int x1, int x2)
void
setFinalLeft(int x1)
void
setFinalTop(int y1)
void
setFinalVertical(int y1, int y2)
void
setFrame(int start, int end, int orientation)

Set the position+dimension of the widget based on starting/ending positions on one dimension.

void
setFrame(int left, int top, int right, int bottom)

Set the position+dimension of the widget given left/top/right/bottom

void
setGoneMargin(ConstraintAnchor.Type type, int goneMargin)

Set the margin to be used when connected to a widget with a visibility of GONE

void
setHasBaseline(boolean hasBaseline)
void
setHeight(int h)

Set the height of the widget

void
setHeightWrapContent(boolean heightWrapContent)

Keep track of wrap_content for height

void
setHorizontalBiasPercent(float horizontalBiasPercent)

Set the horizontal bias percent to apply when we have two opposite constraints of equal strength

void
setHorizontalChainStyle(int horizontalChainStyle)

Set the chain starting from this widget to be packed.

void
setHorizontalDimension(int left, int right)

Set the positions for the horizontal dimension only

void

Set the widget's behaviour for the horizontal dimension

void
setHorizontalMatchStyle(
    int horizontalMatchStyle,
    int min,
    int max,
    float percent
)

Set the horizontal style when MATCH_CONSTRAINT is set

void
setHorizontalWeight(float horizontalWeight)

Set the horizontal weight (only used in chains)

void
setInPlaceholder(boolean inPlaceholder)
void
setInVirtualLayout(boolean inVirtualLayout)
void
setLastMeasureSpec(int horizontal, int vertical)
void
setLength(int length, int orientation)

Set the dimension of a widget in a particular orientation.

void
setMaxHeight(int maxHeight)
void
setMaxWidth(int maxWidth)
void
setMeasureRequested(boolean measureRequested)
void
setMinHeight(int h)

Set the minimum height of the widget

void
setMinWidth(int w)

Set the minimum width of the widget

void
setOffset(int x, int y)

Set the offset of this widget relative to the root widget

void
setOrigin(int x, int y)

Set both the origin in (x, y) of the widget, relative to its container

void

Set the parent of this widget

void

Set the type of the widget (as a String)

void
setVerticalBiasPercent(float verticalBiasPercent)

Set the vertical bias percent to apply when we have two opposite constraints of equal strength

void
setVerticalChainStyle(int verticalChainStyle)

Set the chain starting from this widget to be packed.

void
setVerticalDimension(int top, int bottom)

Set the positions for the vertical dimension only

void

Set the widget's behaviour for the vertical dimension

void
setVerticalMatchStyle(
    int verticalMatchStyle,
    int min,
    int max,
    float percent
)

Set the vertical style when MATCH_CONSTRAINT is set

void
setVerticalWeight(float verticalWeight)

Set the vertical weight (only used in chains)

void
setVisibility(int visibility)

Set the visibility for this widget

void
setWidth(int w)

Set the width of the widget

void
setWidthWrapContent(boolean widthWrapContent)

Keep track of wrap_content for width

void
void
setX(int x)

Set the x position of the widget, relative to its container

void
setY(int y)

Set the y position of the widget, relative to its container

void
setupDimensionRatio(
    boolean hParentWrapContent,
    boolean vParentWrapContent,
    boolean horizontalDimensionFixed,
    boolean verticalDimensionFixed
)

Resolves the dimension ratio parameters (mResolvedDimensionRatioSide &mDimensionRatio)

String

Returns a string representation of the ConstraintWidget

void
updateFromRuns(boolean updateHorizontal, boolean updateVertical)
void
updateFromSolver(LinearSystem system, boolean optimize)

Update the widget from the values generated by the solver

Protected methods

int

Return the x position of the widget, relative to the root (without animation)

int

Return the y position of the widget, relative to the root (without animation)

void
setInBarrier(int orientation, boolean value)

Constants

ANCHOR_BASELINE

Added in 1.1.0-alpha13
public static final int ANCHOR_BASELINE = 4

ANCHOR_BOTTOM

Added in 1.1.0-alpha13
public static final int ANCHOR_BOTTOM = 3

ANCHOR_LEFT

Added in 1.1.0-alpha13
public static final int ANCHOR_LEFT = 0

ANCHOR_RIGHT

Added in 1.1.0-alpha13
public static final int ANCHOR_RIGHT = 1

ANCHOR_TOP

Added in 1.1.0-alpha13
public static final int ANCHOR_TOP = 2

BOTH

Added in 1.1.0-alpha13
public static final int BOTH = 2

CHAIN_PACKED

Added in 1.1.0-alpha13
public static final int CHAIN_PACKED = 2

CHAIN_SPREAD

Added in 1.1.0-alpha13
public static final int CHAIN_SPREAD = 0

CHAIN_SPREAD_INSIDE

Added in 1.1.0-alpha13
public static final int CHAIN_SPREAD_INSIDE = 1

DIRECT

Added in 1.1.0-alpha13
protected static final int DIRECT = 2

GONE

Added in 1.1.0-alpha13
public static final int GONE = 8

HORIZONTAL

Added in 1.1.0-alpha13
public static final int HORIZONTAL = 0

INVISIBLE

Added in 1.1.0-alpha13
public static final int INVISIBLE = 4

MATCH_CONSTRAINT_PERCENT

Added in 1.1.0-alpha13
public static final int MATCH_CONSTRAINT_PERCENT = 2

MATCH_CONSTRAINT_RATIO

Added in 1.1.0-alpha13
public static final int MATCH_CONSTRAINT_RATIO = 3

MATCH_CONSTRAINT_RATIO_RESOLVED

Added in 1.1.0-alpha13
public static final int MATCH_CONSTRAINT_RATIO_RESOLVED = 4

MATCH_CONSTRAINT_SPREAD

Added in 1.1.0-alpha13
public static final int MATCH_CONSTRAINT_SPREAD = 0

MATCH_CONSTRAINT_WRAP

Added in 1.1.0-alpha13
public static final int MATCH_CONSTRAINT_WRAP = 1

SOLVER

Added in 1.1.0-alpha13
protected static final int SOLVER = 1

UNKNOWN

Added in 1.1.0-alpha13
public static final int UNKNOWN = -1

VERTICAL

Added in 1.1.0-alpha13
public static final int VERTICAL = 1

VISIBLE

Added in 1.1.0-alpha13
public static final int VISIBLE = 0

WRAP_BEHAVIOR_HORIZONTAL_ONLY

Added in 1.1.0-alpha13
public static final int WRAP_BEHAVIOR_HORIZONTAL_ONLY = 1

WRAP_BEHAVIOR_INCLUDED

Added in 1.1.0-alpha13
public static final int WRAP_BEHAVIOR_INCLUDED = 0

WRAP_BEHAVIOR_SKIPPED

Added in 1.1.0-alpha13
public static final int WRAP_BEHAVIOR_SKIPPED = 3

WRAP_BEHAVIOR_VERTICAL_ONLY

Added in 1.1.0-alpha13
public static final int WRAP_BEHAVIOR_VERTICAL_ONLY = 2

Public fields

DEFAULT_BIAS

Added in 1.1.0-alpha13
public static float DEFAULT_BIAS

frame

Added in 1.1.0-alpha13
public WidgetFrame frame

horizontalChainRun

Added in 1.1.0-alpha13
public ChainRun horizontalChainRun

horizontalGroup

Added in 1.1.0-alpha13
public int horizontalGroup

isTerminalWidget

Added in 1.1.0-alpha13
public boolean[] isTerminalWidget

mBaseline

Added in 1.1.0-alpha13
public ConstraintAnchor mBaseline

mBottom

Added in 1.1.0-alpha13
public ConstraintAnchor mBottom

mCenter

Added in 1.1.0-alpha13
public ConstraintAnchor mCenter

mCircleConstraintAngle

Added in 1.1.0-alpha13
public float mCircleConstraintAngle

mDimensionRatio

Added in 1.1.0-alpha13
public float mDimensionRatio

mHorizontalResolution

Added in 1.1.0-alpha13
public int mHorizontalResolution

mHorizontalRun

Added in 1.1.0-alpha13
public HorizontalWidgetRun mHorizontalRun

mIsHeightWrapContent

Added in 1.1.0-alpha13
public boolean mIsHeightWrapContent

mIsWidthWrapContent

Added in 1.1.0-alpha13
public boolean mIsWidthWrapContent

mLeft

Added in 1.1.0-alpha13
public ConstraintAnchor mLeft

mListAnchors

Added in 1.1.0-alpha13
public ConstraintAnchor[] mListAnchors

mListDimensionBehaviors

Added in 1.1.0-alpha13
public ConstraintWidget.DimensionBehaviour[] mListDimensionBehaviors

mMatchConstraintDefaultHeight

Added in 1.1.0-alpha13
public int mMatchConstraintDefaultHeight

mMatchConstraintDefaultWidth

Added in 1.1.0-alpha13
public int mMatchConstraintDefaultWidth

mMatchConstraintMaxHeight

Added in 1.1.0-alpha13
public int mMatchConstraintMaxHeight

mMatchConstraintMaxWidth

Added in 1.1.0-alpha13
public int mMatchConstraintMaxWidth

mMatchConstraintMinHeight

Added in 1.1.0-alpha13
public int mMatchConstraintMinHeight

mMatchConstraintMinWidth

Added in 1.1.0-alpha13
public int mMatchConstraintMinWidth

mMatchConstraintPercentHeight

Added in 1.1.0-alpha13
public float mMatchConstraintPercentHeight

mMatchConstraintPercentWidth

Added in 1.1.0-alpha13
public float mMatchConstraintPercentWidth

mParent

Added in 1.1.0-alpha13
public ConstraintWidget mParent

mResolvedMatchConstraintDefault

Added in 1.1.0-alpha13
public int[] mResolvedMatchConstraintDefault

mRight

Added in 1.1.0-alpha13
public ConstraintAnchor mRight

mTop

Added in 1.1.0-alpha13
public ConstraintAnchor mTop

mVerticalResolution

Added in 1.1.0-alpha13
public int mVerticalResolution

mVerticalRun

Added in 1.1.0-alpha13
public VerticalWidgetRun mVerticalRun

mWeight

Added in 1.1.0-alpha13
public float[] mWeight

measured

Added in 1.1.0-alpha13
public boolean measured

run

Added in 1.1.0-alpha13
public WidgetRun[] run

stringId

Added in 1.1.0-alpha13
public String stringId

verticalChainRun

Added in 1.1.0-alpha13
public ChainRun verticalChainRun

verticalGroup

Added in 1.1.0-alpha13
public int verticalGroup

Protected fields

mAnchors

Added in 1.1.0-alpha13
protected ArrayList<ConstraintAnchormAnchors

mDimensionRatioSide

Added in 1.1.0-alpha13
protected int mDimensionRatioSide

mListNextMatchConstraintsWidget

Added in 1.1.0-alpha13
protected ConstraintWidget[] mListNextMatchConstraintsWidget

mMinHeight

Added in 1.1.0-alpha13
protected int mMinHeight

mMinWidth

Added in 1.1.0-alpha13
protected int mMinWidth

mNextChainWidget

Added in 1.1.0-alpha13
protected ConstraintWidget[] mNextChainWidget

mOffsetX

Added in 1.1.0-alpha13
protected int mOffsetX

mOffsetY

Added in 1.1.0-alpha13
protected int mOffsetY

mX

Added in 1.1.0-alpha13
protected int mX

mY

Added in 1.1.0-alpha13
protected int mY

Public constructors

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget()

Default constructor

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget(String debugName)

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget(int width, int height)

Constructor

Parameters
int width

width of the layout

int height

height of the layout

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget(String debugName, int width, int height)

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget(int x, int y, int width, int height)

Constructor

Parameters
int x

x position

int y

y position

int width

width of the layout

int height

height of the layout

ConstraintWidget

Added in 1.1.0-alpha13
public ConstraintWidget(String debugName, int x, int y, int width, int height)

Public methods

addChildrenToSolverByDependency

Added in 1.1.0-alpha13
public void addChildrenToSolverByDependency(
    ConstraintWidgetContainer container,
    LinearSystem system,
    HashSet<ConstraintWidget> widgets,
    int orientation,
    boolean addSelf
)

addToSolver

Added in 1.1.0-alpha13
public void addToSolver(LinearSystem system, boolean optimize)

Add this widget to the solver

Parameters
LinearSystem system

the solver we want to add the widget to

boolean optimize

true if OPTIMIZATION_GRAPH is on

allowedInBarrier

Added in 1.1.0-alpha13
public boolean allowedInBarrier()

Returns true if this widget should be used in a barrier

connect

Added in 1.1.0-alpha13
public void connect(
    ConstraintAnchor.Type constraintFrom,
    ConstraintWidget target,
    ConstraintAnchor.Type constraintTo
)

Connect a given anchor of this widget to another anchor of a target widget

Parameters
ConstraintAnchor.Type constraintFrom

which anchor of this widget to connect from

ConstraintWidget target

the target widget

ConstraintAnchor.Type constraintTo

the target anchor on the target widget

connect

Added in 1.1.0-alpha13
public void connect(ConstraintAnchor from, ConstraintAnchor to, int margin)

Connect the given anchors together (the from anchor should be owned by this widget)

Parameters
ConstraintAnchor from

the anchor we are connecting from (of this widget)

ConstraintAnchor to

the anchor we are connecting to

int margin

how much margin we want to have

connect

Added in 1.1.0-alpha13
public void connect(
    ConstraintAnchor.Type constraintFrom,
    ConstraintWidget target,
    ConstraintAnchor.Type constraintTo,
    int margin
)

Connect a given anchor of this widget to another anchor of a target widget

Parameters
ConstraintAnchor.Type constraintFrom

which anchor of this widget to connect from

ConstraintWidget target

the target widget

ConstraintAnchor.Type constraintTo

the target anchor on the target widget

int margin

how much margin we want to keep as a minimum distance between the two anchors

connectCircularConstraint

Added in 1.1.0-alpha13
public void connectCircularConstraint(
    ConstraintWidget target,
    float angle,
    int radius
)

Set a circular constraint

Parameters
ConstraintWidget target

the target widget we will use as the center of the circle

float angle

the angle (from 0 to 360)

int radius

the radius used

copy

Added in 1.1.0-alpha13
public void copy(
    ConstraintWidget src,
    HashMap<ConstraintWidgetConstraintWidget> map
)

createObjectVariables

Added in 1.1.0-alpha13
public void createObjectVariables(LinearSystem system)

Create all the system variables for this widget

ensureMeasureRequested

Added in 1.1.0-alpha13
public void ensureMeasureRequested()

ensureWidgetRuns

Added in 1.1.0-alpha13
public void ensureWidgetRuns()

getAnchor

Added in 1.1.0-alpha13
public ConstraintAnchor getAnchor(ConstraintAnchor.Type anchorType)

Given a type of anchor, returns the corresponding anchor.

Parameters
ConstraintAnchor.Type anchorType

type of the anchor (LEFT, TOP, RIGHT, BOTTOM, BASELINE, CENTER_X, CENTER_Y)

Returns
ConstraintAnchor

the matching anchor

getAnchors

Added in 1.1.0-alpha13
public ArrayList<ConstraintAnchorgetAnchors()

Return the array of anchors of this widget

Returns
ArrayList<ConstraintAnchor>

array of anchors

getBaselineDistance

Added in 1.1.0-alpha13
public int getBaselineDistance()

Return the baseline distance relative to the top of the widget

Returns
int

baseline

getBiasPercent

Added in 1.1.0-alpha13
public float getBiasPercent(int orientation)

Return the percentage bias that is used when two opposite connections exist of the same strength in a particular orientation.

Parameters
int orientation

Orientation HORIZONTAL/VERTICAL.

Returns
float

Respective percentage bias.

getBottom

Added in 1.1.0-alpha13
public int getBottom()

Return the bottom position of the widget

Returns
int

bottom position of the widget

getCompanionWidget

Added in 1.1.0-alpha13
public Object getCompanionWidget()

Return the companion widget. Typically, this would be the real widget we represent with this instance of ConstraintWidget.

Returns
Object

the companion widget, if set.

getContainerItemSkip

Added in 1.1.0-alpha13
public int getContainerItemSkip()

Accessor for the skip value

Returns
int

skip value

getDebugName

Added in 1.1.0-alpha13
public String getDebugName()

Returns the name of this widget (used for debug purposes)

Returns
String

the debug name

getDimensionBehaviour

Added in 1.1.0-alpha13
public ConstraintWidget.DimensionBehaviour getDimensionBehaviour(int orientation)

Get the widget's DimensionBehaviour in an specific orientation.

getDimensionRatio

Added in 1.1.0-alpha13
public float getDimensionRatio()

Return the current ratio of this widget

Returns
float

the dimension ratio (HORIZONTAL, VERTICAL, or UNKNOWN)

getDimensionRatioSide

Added in 1.1.0-alpha13
public int getDimensionRatioSide()

Return the current side on which ratio will be applied

Returns
int

HORIZONTAL, VERTICAL, or UNKNOWN

getHasBaseline

Added in 1.1.0-alpha13
public boolean getHasBaseline()

getHeight

Added in 1.1.0-alpha13
public int getHeight()

Return the height of the widget

Returns
int

height height

getHorizontalBiasPercent

Added in 1.1.0-alpha13
public float getHorizontalBiasPercent()

Return the horizontal percentage bias that is used when two opposite connections exist of the same strength.

Returns
float

horizontal percentage bias

getHorizontalChainControlWidget

Added in 1.1.0-alpha13
public ConstraintWidget getHorizontalChainControlWidget()

if in a horizontal chain return the left most widget in the chain.

Returns
ConstraintWidget

left most widget in chain or null

getHorizontalChainStyle

Added in 1.1.0-alpha13
public int getHorizontalChainStyle()

get the chain starting from this widget to be packed. The horizontal bias will control how elements of the chain are positioned.

Returns
int

Horizontal Chain Style

getHorizontalDimensionBehaviour

Added in 1.1.0-alpha13
public ConstraintWidget.DimensionBehaviour getHorizontalDimensionBehaviour()

Accessor for the horizontal dimension behaviour

Returns
ConstraintWidget.DimensionBehaviour

dimension behaviour

getHorizontalMargin

Added in 1.1.0-alpha13
public int getHorizontalMargin()

Returns all the horizontal margin of the widget.

getLastHorizontalMeasureSpec

Added in 1.1.0-alpha13
public int getLastHorizontalMeasureSpec()

getLastVerticalMeasureSpec

Added in 1.1.0-alpha13
public int getLastVerticalMeasureSpec()

getLeft

Added in 1.1.0-alpha13
public int getLeft()

Return the left position of the widget (similar to getX)

Returns
int

left position of the widget

getLength

Added in 1.1.0-alpha13
public int getLength(int orientation)

Get a dimension of the widget in a particular orientation.

Returns
int

The dimension of the specified orientation.

getMaxHeight

Added in 1.1.0-alpha13
public int getMaxHeight()

getMaxWidth

Added in 1.1.0-alpha13
public int getMaxWidth()

getMinHeight

Added in 1.1.0-alpha13
public int getMinHeight()

Return the minimum height of the widget

Returns
int

minimum height

getMinWidth

Added in 1.1.0-alpha13
public int getMinWidth()

Return the minimum width of the widget

Returns
int

minimum width

getNextChainMember

Added in 1.1.0-alpha13
public ConstraintWidget getNextChainMember(int orientation)

Return the next chain member if one exists

Parameters
int orientation

HORIZONTAL or VERTICAL

Returns
ConstraintWidget

the next chain member or null if we are the last chain element

getOptimizerWrapHeight

Added in 1.1.0-alpha13
public int getOptimizerWrapHeight()

getOptimizerWrapWidth

Added in 1.1.0-alpha13
public int getOptimizerWrapWidth()

getParent

Added in 1.1.0-alpha13
public ConstraintWidget getParent()

Returns the parent of this widget if there is one

Returns
ConstraintWidget

parent

getPreviousChainMember

Added in 1.1.0-alpha13
public ConstraintWidget getPreviousChainMember(int orientation)

Return the previous chain member if one exists

Parameters
int orientation

HORIZONTAL or VERTICAL

Returns
ConstraintWidget

the previous chain member or null if we are the first chain element

getRight

Added in 1.1.0-alpha13
public int getRight()

Return the right position of the widget

Returns
int

right position of the widget

getRun

Added in 1.1.0-alpha13
public WidgetRun getRun(int orientation)

getSceneString

Added in 1.1.0-alpha13
public void getSceneString(StringBuilder ret)

getTop

Added in 1.1.0-alpha13
public int getTop()

Return the top position of the widget (similar to getY)

Returns
int

top position of the widget

getType

Added in 1.1.0-alpha13
public String getType()

Returns the type string if set

Returns
String

type (null if not set)

getVerticalBiasPercent

Added in 1.1.0-alpha13
public float getVerticalBiasPercent()

Return the vertical percentage bias that is used when two opposite connections exist of the same strength.

Returns
float

vertical percentage bias

getVerticalChainControlWidget

Added in 1.1.0-alpha13
public ConstraintWidget getVerticalChainControlWidget()

if in a vertical chain return the top most widget in the chain.

Returns
ConstraintWidget

top most widget in chain or null

getVerticalChainStyle

Added in 1.1.0-alpha13
public int getVerticalChainStyle()

Set the chain starting from this widget to be packed. The vertical bias will control how elements of the chain are positioned.

getVerticalDimensionBehaviour

Added in 1.1.0-alpha13
public ConstraintWidget.DimensionBehaviour getVerticalDimensionBehaviour()

Accessor for the vertical dimension behaviour

Returns
ConstraintWidget.DimensionBehaviour

dimension behaviour

getVerticalMargin

Added in 1.1.0-alpha13
public int getVerticalMargin()

Returns all the vertical margin of the widget

getVisibility

Added in 1.1.0-alpha13
public int getVisibility()

Returns the current visibility value for this widget

Returns
int

the visibility (VISIBLE, INVISIBLE, or GONE)

getWidth

Added in 1.1.0-alpha13
public int getWidth()

Return the width of the widget

Returns
int

width width

getWrapBehaviorInParent

Added in 1.1.0-alpha13
public int getWrapBehaviorInParent()

getX

Added in 1.1.0-alpha13
public int getX()

Return the x position of the widget, relative to its container

Returns
int

x position

getY

Added in 1.1.0-alpha13
public int getY()

Return the y position of the widget, relative to its container

Returns
int

y position

hasBaseline

Added in 1.1.0-alpha13
public boolean hasBaseline()

Return true if this widget has a baseline

Returns
boolean

true if the widget has a baseline, false otherwise

hasDanglingDimension

Added in 1.1.0-alpha13
public boolean hasDanglingDimension(int orientation)

hasDependencies

Added in 1.1.0-alpha13
public boolean hasDependencies()

hasDimensionOverride

Added in 1.1.0-alpha13
public boolean hasDimensionOverride()

hasResolvedTargets

Added in 1.1.0-alpha13
public boolean hasResolvedTargets(int orientation, int size)

immediateConnect

Added in 1.1.0-alpha13
public void immediateConnect(
    ConstraintAnchor.Type startType,
    ConstraintWidget target,
    ConstraintAnchor.Type endType,
    int margin,
    int goneMargin
)

Immediate connection to an anchor without any checks.

Parameters
ConstraintAnchor.Type startType

The type of anchor on this widget

ConstraintWidget target

The target widget

ConstraintAnchor.Type endType

The type of anchor on the target widget

int margin

How much margin we want to keep as a minimum distance between the two anchors

int goneMargin

How much margin we want to keep if the target is set to View.GONE

isAnimated

Added in 1.1.0-alpha13
public boolean isAnimated()

Returns if this widget is animated. Currently only affects gone behaviour

Returns
boolean

true if ConstraintWidget is used in Animation

isHeightWrapContent

Added in 1.1.0-alpha13
public boolean isHeightWrapContent()

Returns true if height is set to wrap_content

isHorizontalSolvingPassDone

Added in 1.1.0-alpha13
public boolean isHorizontalSolvingPassDone()

isInBarrier

Added in 1.1.0-alpha13
public boolean isInBarrier(int orientation)

isInHorizontalChain

Added in 1.1.0-alpha13
public boolean isInHorizontalChain()

Test if you are in a Horizontal chain

Returns
boolean

true if in a horizontal chain

isInPlaceholder

Added in 1.1.0-alpha13
public boolean isInPlaceholder()

isInVerticalChain

Added in 1.1.0-alpha13
public boolean isInVerticalChain()

Test if you are in a vertical chain

Returns
boolean

true if in a vertical chain

isInVirtualLayout

Added in 1.1.0-alpha13
public boolean isInVirtualLayout()

isMeasureRequested

Added in 1.1.0-alpha13
public boolean isMeasureRequested()

isResolvedHorizontally

Added in 1.1.0-alpha13
public boolean isResolvedHorizontally()

isResolvedVertically

Added in 1.1.0-alpha13
public boolean isResolvedVertically()

isRoot

Added in 1.1.0-alpha13
public boolean isRoot()

Returns true if the widget is the root widget

Returns
boolean

true if root widget, false otherwise

isSpreadHeight

Added in 1.1.0-alpha13
public boolean isSpreadHeight()

isSpreadWidth

Added in 1.1.0-alpha13
public boolean isSpreadWidth()

isVerticalSolvingPassDone

Added in 1.1.0-alpha13
public boolean isVerticalSolvingPassDone()

isWidthWrapContent

Added in 1.1.0-alpha13
public boolean isWidthWrapContent()

Returns true if width is set to wrap_content

markHorizontalSolvingPassDone

Added in 1.1.0-alpha13
public void markHorizontalSolvingPassDone()

markVerticalSolvingPassDone

Added in 1.1.0-alpha13
public void markVerticalSolvingPassDone()

oppositeDimensionDependsOn

Added in 1.1.0-alpha13
public boolean oppositeDimensionDependsOn(int orientation)

oppositeDimensionsTied

Added in 1.1.0-alpha13
public boolean oppositeDimensionsTied()

reset

Added in 1.1.0-alpha13
public void reset()

resetAllConstraints

Added in 1.1.0-alpha13
public void resetAllConstraints()

Reset all the constraints set on this widget

resetAnchor

Added in 1.1.0-alpha13
public void resetAnchor(ConstraintAnchor anchor)

Reset the given anchor

Parameters
ConstraintAnchor anchor

the anchor we want to reset

resetAnchors

Added in 1.1.0-alpha13
public void resetAnchors()

Reset all connections

resetFinalResolution

Added in 1.1.0-alpha13
public void resetFinalResolution()

resetSolverVariables

Added in 1.1.0-alpha13
public void resetSolverVariables(Cache cache)

Reset the solver variables of the anchors

resetSolvingPassFlag

Added in 1.1.0-alpha13
public void resetSolvingPassFlag()

serialize

Added in 1.1.0-alpha13
public StringBuilder serialize(StringBuilder ret)

Serialize the anchors for JSON5 output

Parameters
StringBuilder ret

StringBuilder to be populated

Returns
StringBuilder

the same string builder to alow chaining

setAnimated

Added in 1.1.0-alpha13
public void setAnimated(boolean animated)

Set if this widget is animated. Currently only affects gone behaviour

Parameters
boolean animated

if true the widget must be positioned correctly when not visible

setBaselineDistance

Added in 1.1.0-alpha13
public void setBaselineDistance(int baseline)

Set the baseline distance relative to the top of the widget

Parameters
int baseline

the distance of the baseline relative to the widget's top

setCompanionWidget

Added in 1.1.0-alpha13
public void setCompanionWidget(Object companion)

Set the companion widget. Typically, this would be the real widget we represent with this instance of ConstraintWidget.

setContainerItemSkip

Added in 1.1.0-alpha13
public void setContainerItemSkip(int skip)

Set the skip value for this widget. This can be used when a widget is in a container, so that container can position the widget as if it was positioned further in the list of widgets. For example, with Table, this is used to skip empty cells (the widget after an empty cell will have a skip value of one)

setDebugName

Added in 1.1.0-alpha13
public void setDebugName(String name)

Set the debug name of this widget

setDebugSolverName

Added in 1.1.0-alpha13
public void setDebugSolverName(LinearSystem system, String name)

Utility debug function. Sets the names of the anchors in the solver given a widget's name. The given name is used as a prefix, resulting in anchors' names of the form:

  • {name}.left
  • {name}.top
  • {name}.right
  • {name}.bottom
  • {name}.baseline
Parameters
LinearSystem system

solver used

String name

name of the widget

setDimension

Added in 1.1.0-alpha13
public void setDimension(int w, int h)

Set both width and height of the widget

Parameters
int w

width

int h

height

setDimensionRatio

Added in 1.1.0-alpha13
public void setDimensionRatio(String ratio)

Set the ratio of the widget

Parameters
String ratio

given string of format [H|V],[float|x:y] or [float|x:y]

setDimensionRatio

Added in 1.1.0-alpha13
public void setDimensionRatio(float ratio, int dimensionRatioSide)

Set the ratio of the widget The ratio will be applied if at least one of the dimension (width or height) is set to a behaviour of DimensionBehaviour.MATCH_CONSTRAINT -- the dimension's value will be set to the other dimension * ratio.

Parameters
float ratio

A float value that describes W/H or H/W depending on the provided dimensionRatioSide

int dimensionRatioSide

The side the ratio should be calculated on, HORIZONTAL, VERTICAL, or UNKNOWN

setFinalBaseline

Added in 1.1.0-alpha13
public void setFinalBaseline(int baselineValue)

setFinalFrame

Added in 1.1.0-alpha13
public void setFinalFrame(
    int left,
    int top,
    int right,
    int bottom,
    int baseline,
    int orientation
)

setFinalHorizontal

Added in 1.1.0-alpha13
public void setFinalHorizontal(int x1, int x2)

setFinalLeft

Added in 1.1.0-alpha13
public void setFinalLeft(int x1)

setFinalTop

Added in 1.1.0-alpha13
public void setFinalTop(int y1)

setFinalVertical

Added in 1.1.0-alpha13
public void setFinalVertical(int y1, int y2)

setFrame

Added in 1.1.0-alpha13
public void setFrame(int start, int end, int orientation)

Set the position+dimension of the widget based on starting/ending positions on one dimension.

Parameters
int start

Left/Top side position of the widget.

int end

Right/Bottom side position of the widget.

int orientation

Orientation being set (HORIZONTAL/VERTICAL).

setFrame

Added in 1.1.0-alpha13
public void setFrame(int left, int top, int right, int bottom)

Set the position+dimension of the widget given left/top/right/bottom

Parameters
int left

left side position of the widget

int top

top side position of the widget

int right

right side position of the widget

int bottom

bottom side position of the widget

setGoneMargin

Added in 1.1.0-alpha13
public void setGoneMargin(ConstraintAnchor.Type type, int goneMargin)

Set the margin to be used when connected to a widget with a visibility of GONE

Parameters
ConstraintAnchor.Type type

the anchor to set the margin on

int goneMargin

the margin value to use

setHasBaseline

Added in 1.1.0-alpha13
public void setHasBaseline(boolean hasBaseline)

setHeight

Added in 1.1.0-alpha13
public void setHeight(int h)

Set the height of the widget

Parameters
int h

height

setHeightWrapContent

Added in 1.1.0-alpha13
public void setHeightWrapContent(boolean heightWrapContent)

Keep track of wrap_content for height

setHorizontalBiasPercent

Added in 1.1.0-alpha13
public void setHorizontalBiasPercent(float horizontalBiasPercent)

Set the horizontal bias percent to apply when we have two opposite constraints of equal strength

Parameters
float horizontalBiasPercent

the percentage used

setHorizontalChainStyle

Added in 1.1.0-alpha13
public void setHorizontalChainStyle(int horizontalChainStyle)

Set the chain starting from this widget to be packed. The horizontal bias will control how elements of the chain are positioned.

Parameters
int horizontalChainStyle

(CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED)

setHorizontalDimension

Added in 1.1.0-alpha13
public void setHorizontalDimension(int left, int right)

Set the positions for the horizontal dimension only

Parameters
int left

left side position of the widget

int right

right side position of the widget

setHorizontalDimensionBehaviour

Added in 1.1.0-alpha13
public void setHorizontalDimensionBehaviour(
    ConstraintWidget.DimensionBehaviour behaviour
)

Set the widget's behaviour for the horizontal dimension

Parameters
ConstraintWidget.DimensionBehaviour behaviour

the horizontal dimension's behaviour

setHorizontalMatchStyle

Added in 1.1.0-alpha13
public void setHorizontalMatchStyle(
    int horizontalMatchStyle,
    int min,
    int max,
    float percent
)

Set the horizontal style when MATCH_CONSTRAINT is set

Parameters
int horizontalMatchStyle

MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAP

int min

minimum value

int max

maximum value

float percent

Percent width

setHorizontalWeight

Added in 1.1.0-alpha13
public void setHorizontalWeight(float horizontalWeight)

Set the horizontal weight (only used in chains)

Parameters
float horizontalWeight

Floating point value weight

setInPlaceholder

Added in 1.1.0-alpha13
public void setInPlaceholder(boolean inPlaceholder)

setInVirtualLayout

Added in 1.1.0-alpha13
public void setInVirtualLayout(boolean inVirtualLayout)

setLastMeasureSpec

Added in 1.1.0-alpha13
public void setLastMeasureSpec(int horizontal, int vertical)

setLength

Added in 1.1.0-alpha13
public void setLength(int length, int orientation)

Set the dimension of a widget in a particular orientation.

Parameters
int length

Size of the dimension.

int orientation

HORIZONTAL or VERTICAL

setMaxHeight

Added in 1.1.0-alpha13
public void setMaxHeight(int maxHeight)

setMaxWidth

Added in 1.1.0-alpha13
public void setMaxWidth(int maxWidth)

setMeasureRequested

Added in 1.1.0-alpha13
public void setMeasureRequested(boolean measureRequested)

setMinHeight

Added in 1.1.0-alpha13
public void setMinHeight(int h)

Set the minimum height of the widget

Parameters
int h

minimum height

setMinWidth

Added in 1.1.0-alpha13
public void setMinWidth(int w)

Set the minimum width of the widget

Parameters
int w

minimum width

setOffset

Added in 1.1.0-alpha13
public void setOffset(int x, int y)

Set the offset of this widget relative to the root widget

Parameters
int x

horizontal offset

int y

vertical offset

setOrigin

Added in 1.1.0-alpha13
public void setOrigin(int x, int y)

Set both the origin in (x, y) of the widget, relative to its container

Parameters
int x

x position

int y

y position

setParent

Added in 1.1.0-alpha13
public void setParent(ConstraintWidget widget)

Set the parent of this widget

Parameters
ConstraintWidget widget

parent

setType

Added in 1.1.0-alpha13
public void setType(String type)

Set the type of the widget (as a String)

Parameters
String type

type of the widget

setVerticalBiasPercent

Added in 1.1.0-alpha13
public void setVerticalBiasPercent(float verticalBiasPercent)

Set the vertical bias percent to apply when we have two opposite constraints of equal strength

Parameters
float verticalBiasPercent

the percentage used

setVerticalChainStyle

Added in 1.1.0-alpha13
public void setVerticalChainStyle(int verticalChainStyle)

Set the chain starting from this widget to be packed. The vertical bias will control how elements of the chain are positioned.

Parameters
int verticalChainStyle

(CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, CHAIN_PACKED)

setVerticalDimension

Added in 1.1.0-alpha13
public void setVerticalDimension(int top, int bottom)

Set the positions for the vertical dimension only

Parameters
int top

top side position of the widget

int bottom

bottom side position of the widget

setVerticalDimensionBehaviour

Added in 1.1.0-alpha13
public void setVerticalDimensionBehaviour(
    ConstraintWidget.DimensionBehaviour behaviour
)

Set the widget's behaviour for the vertical dimension

Parameters
ConstraintWidget.DimensionBehaviour behaviour

the vertical dimension's behaviour

setVerticalMatchStyle

Added in 1.1.0-alpha13
public void setVerticalMatchStyle(
    int verticalMatchStyle,
    int min,
    int max,
    float percent
)

Set the vertical style when MATCH_CONSTRAINT is set

Parameters
int verticalMatchStyle

MATCH_CONSTRAINT_SPREAD or MATCH_CONSTRAINT_WRAP

int min

minimum value

int max

maximum value

float percent

Percent height

setVerticalWeight

Added in 1.1.0-alpha13
public void setVerticalWeight(float verticalWeight)

Set the vertical weight (only used in chains)

Parameters
float verticalWeight

Floating point value weight

setVisibility

Added in 1.1.0-alpha13
public void setVisibility(int visibility)

Set the visibility for this widget

Parameters
int visibility

either VISIBLE, INVISIBLE, or GONE

setWidth

Added in 1.1.0-alpha13
public void setWidth(int w)

Set the width of the widget

Parameters
int w

width

setWidthWrapContent

Added in 1.1.0-alpha13
public void setWidthWrapContent(boolean widthWrapContent)

Keep track of wrap_content for width

setWrapBehaviorInParent

Added in 1.1.0-alpha13
public void setWrapBehaviorInParent(int behavior)

setX

Added in 1.1.0-alpha13
public void setX(int x)

Set the x position of the widget, relative to its container

Parameters
int x

x position

setY

Added in 1.1.0-alpha13
public void setY(int y)

Set the y position of the widget, relative to its container

Parameters
int y

y position

setupDimensionRatio

Added in 1.1.0-alpha13
public void setupDimensionRatio(
    boolean hParentWrapContent,
    boolean vParentWrapContent,
    boolean horizontalDimensionFixed,
    boolean verticalDimensionFixed
)

Resolves the dimension ratio parameters (mResolvedDimensionRatioSide &mDimensionRatio)

Parameters
boolean hParentWrapContent

true if parent is in wrap content horizontally

boolean vParentWrapContent

true if parent is in wrap content vertically

boolean horizontalDimensionFixed

true if this widget horizontal dimension is fixed

boolean verticalDimensionFixed

true if this widget vertical dimension is fixed

toString

public String toString()

Returns a string representation of the ConstraintWidget

Returns
String

string representation of the widget

updateFromRuns

Added in 1.1.0-alpha13
public void updateFromRuns(boolean updateHorizontal, boolean updateVertical)

updateFromSolver

Added in 1.1.0-alpha13
public void updateFromSolver(LinearSystem system, boolean optimize)

Update the widget from the values generated by the solver

Parameters
LinearSystem system

the solver we get the values from.

boolean optimize

true if OPTIMIZATION_GRAPH is on

Protected methods

getRootX

Added in 1.1.0-alpha13
protected int getRootX()

Return the x position of the widget, relative to the root (without animation)

Returns
int

x position

getRootY

Added in 1.1.0-alpha13
protected int getRootY()

Return the y position of the widget, relative to the root (without animation)

setInBarrier

Added in 1.1.0-alpha13
protected void setInBarrier(int orientation, boolean value)