public class

VirtualLayout

extends HelperWidget

 java.lang.Object

androidx.constraintlayout.core.widgets.ConstraintWidget

androidx.constraintlayout.core.widgets.HelperWidget

↳androidx.constraintlayout.core.widgets.VirtualLayout

Subclasses:

Flow, Placeholder, GridCore

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-beta01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-beta01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

Base class for Virtual layouts

Summary

Fields
protected BasicMeasure.MeasuremMeasure

from HelperWidgetmWidgets[], mWidgetsCount
from ConstraintWidgetANCHOR_BASELINE, ANCHOR_BOTTOM, ANCHOR_LEFT, ANCHOR_RIGHT, ANCHOR_TOP, BOTH, CHAIN_PACKED, CHAIN_SPREAD, CHAIN_SPREAD_INSIDE, DEFAULT_BIAS, DIRECT, frame, GONE, HORIZONTAL, horizontalChainRun, horizontalGroup, INVISIBLE, isTerminalWidget[], mAnchors, MATCH_CONSTRAINT_PERCENT, MATCH_CONSTRAINT_RATIO, MATCH_CONSTRAINT_RATIO_RESOLVED, MATCH_CONSTRAINT_SPREAD, MATCH_CONSTRAINT_WRAP, mBaseline, mBottom, mCenter, mCircleConstraintAngle, mDimensionRatio, mDimensionRatioSide, measured, mHorizontalResolution, mHorizontalRun, mIsHeightWrapContent, mIsWidthWrapContent, mLeft, mListAnchors[], mListDimensionBehaviors[], mListNextMatchConstraintsWidget[], mMatchConstraintDefaultHeight, mMatchConstraintDefaultWidth, mMatchConstraintMaxHeight, mMatchConstraintMaxWidth, mMatchConstraintMinHeight, mMatchConstraintMinWidth, mMatchConstraintPercentHeight, mMatchConstraintPercentWidth, mMinHeight, mMinWidth, mNextChainWidget[], mOffsetX, mOffsetY, mParent, mResolvedMatchConstraintDefault[], mRight, mTop, mVerticalResolution, mVerticalRun, mWeight[], mX, mY, run[], SOLVER, stringId, UNKNOWN, VERTICAL, verticalChainRun, verticalGroup, VISIBLE, WRAP_BEHAVIOR_HORIZONTAL_ONLY, WRAP_BEHAVIOR_INCLUDED, WRAP_BEHAVIOR_SKIPPED, WRAP_BEHAVIOR_VERTICAL_ONLY
Constructors
publicVirtualLayout()

Methods
public voidapplyRtl(boolean isRtl)

public voidcaptureWidgets()

public booleancontains(java.util.HashSet<ConstraintWidget> widgets)

public intgetMeasuredHeight()

public intgetMeasuredWidth()

public intgetPaddingBottom()

public intgetPaddingLeft()

public intgetPaddingRight()

public intgetPaddingTop()

protected voidmeasure(ConstraintWidget widget, ConstraintWidget.DimensionBehaviour horizontalBehavior, int horizontalDimension, ConstraintWidget.DimensionBehaviour verticalBehavior, int verticalDimension)

public voidmeasure(int widthMode, int widthSize, int heightMode, int heightSize)

protected booleanmeasureChildren()

protected voidneedsCallbackFromSolver(boolean value)

public booleanneedSolverPass()

public voidsetMeasure(int width, int height)

public voidsetPadding(int value)

public voidsetPaddingBottom(int value)

public voidsetPaddingEnd(int value)

public voidsetPaddingLeft(int value)

public voidsetPaddingRight(int value)

public voidsetPaddingStart(int value)

public voidsetPaddingTop(int value)

public voidupdateConstraints(ConstraintWidgetContainer container)

from HelperWidgetadd, addDependents, copy, findGroupInDependents, removeAllIds
from ConstraintWidgetaddChildrenToSolverByDependency, addToSolver, allowedInBarrier, connect, connect, connect, connectCircularConstraint, createObjectVariables, ensureMeasureRequested, ensureWidgetRuns, getAnchor, getAnchors, getBaselineDistance, getBiasPercent, getBottom, getCompanionWidget, getContainerItemSkip, getDebugName, getDimensionBehaviour, getDimensionRatio, getDimensionRatioSide, getHasBaseline, getHeight, getHorizontalBiasPercent, getHorizontalChainControlWidget, getHorizontalChainStyle, getHorizontalDimensionBehaviour, getHorizontalMargin, getLastHorizontalMeasureSpec, getLastVerticalMeasureSpec, getLeft, getLength, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getNextChainMember, getOptimizerWrapHeight, getOptimizerWrapWidth, getParent, getPreviousChainMember, getRight, getRootX, getRootY, getRun, getSceneString, getTop, getType, getVerticalBiasPercent, getVerticalChainControlWidget, getVerticalChainStyle, getVerticalDimensionBehaviour, getVerticalMargin, getVisibility, getWidth, getWrapBehaviorInParent, getX, getY, hasBaseline, hasDanglingDimension, hasDependencies, hasDimensionOverride, hasResolvedTargets, immediateConnect, isAnimated, isHeightWrapContent, isHorizontalSolvingPassDone, isInBarrier, isInHorizontalChain, isInPlaceholder, isInVerticalChain, isInVirtualLayout, isMeasureRequested, isResolvedHorizontally, isResolvedVertically, isRoot, isSpreadHeight, isSpreadWidth, isVerticalSolvingPassDone, isWidthWrapContent, markHorizontalSolvingPassDone, markVerticalSolvingPassDone, oppositeDimensionDependsOn, oppositeDimensionsTied, reset, resetAllConstraints, resetAnchor, resetAnchors, resetFinalResolution, resetSolverVariables, resetSolvingPassFlag, serialize, setAnimated, setBaselineDistance, setCompanionWidget, setContainerItemSkip, setDebugName, setDebugSolverName, setDimension, setDimensionRatio, setDimensionRatio, setFinalBaseline, setFinalFrame, setFinalHorizontal, setFinalLeft, setFinalTop, setFinalVertical, setFrame, setFrame, setGoneMargin, setHasBaseline, setHeight, setHeightWrapContent, setHorizontalBiasPercent, setHorizontalChainStyle, setHorizontalDimension, setHorizontalDimensionBehaviour, setHorizontalMatchStyle, setHorizontalWeight, setInBarrier, setInPlaceholder, setInVirtualLayout, setLastMeasureSpec, setLength, setMaxHeight, setMaxWidth, setMeasureRequested, setMinHeight, setMinWidth, setOffset, setOrigin, setParent, setType, setupDimensionRatio, setVerticalBiasPercent, setVerticalChainStyle, setVerticalDimension, setVerticalDimensionBehaviour, setVerticalMatchStyle, setVerticalWeight, setVisibility, setWidth, setWidthWrapContent, setWrapBehaviorInParent, setX, setY, toString, updateFromRuns, updateFromSolver
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Fields

protected BasicMeasure.Measure mMeasure

Constructors

public VirtualLayout()

Methods

public void setPadding(int value)

public void setPaddingStart(int value)

public void setPaddingEnd(int value)

public void setPaddingLeft(int value)

public void applyRtl(boolean isRtl)

public void setPaddingTop(int value)

public void setPaddingRight(int value)

public void setPaddingBottom(int value)

public int getPaddingTop()

public int getPaddingBottom()

public int getPaddingLeft()

public int getPaddingRight()

protected void needsCallbackFromSolver(boolean value)

public boolean needSolverPass()

public void measure(int widthMode, int widthSize, int heightMode, int heightSize)

public void updateConstraints(ConstraintWidgetContainer container)

public void captureWidgets()

public int getMeasuredWidth()

public int getMeasuredHeight()

public void setMeasure(int width, int height)

protected boolean measureChildren()

protected void measure(ConstraintWidget widget, ConstraintWidget.DimensionBehaviour horizontalBehavior, int horizontalDimension, ConstraintWidget.DimensionBehaviour verticalBehavior, int verticalDimension)

public boolean contains(java.util.HashSet<ConstraintWidget> widgets)

Source

/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package androidx.constraintlayout.core.widgets;

import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure;

import java.util.HashSet;

/**
 * Base class for Virtual layouts
 */
public class VirtualLayout extends HelperWidget {

    private int mPaddingTop = 0;
    private int mPaddingBottom = 0;
    @SuppressWarnings("unused") private int mPaddingLeft = 0;
    @SuppressWarnings("unused") private int mPaddingRight = 0;
    @SuppressWarnings("unused") private int mPaddingStart = 0;
    private int mPaddingEnd = 0;
    private int mResolvedPaddingLeft = 0;
    private int mResolvedPaddingRight = 0;

    private boolean mNeedsCallFromSolver = false;
    private int mMeasuredWidth = 0;
    private int mMeasuredHeight = 0;

    protected BasicMeasure.Measure mMeasure = new BasicMeasure.Measure();

    /////////////////////////////////////////////////////////////////////////////////////////////
    // Accessors
    /////////////////////////////////////////////////////////////////////////////////////////////

    // @TODO: add description
    public void setPadding(int value) {
        mPaddingLeft = value;
        mPaddingTop = value;
        mPaddingRight = value;
        mPaddingBottom = value;
        mPaddingStart = value;
        mPaddingEnd = value;
    }

    // @TODO: add description
    public void setPaddingStart(int value) {
        mPaddingStart = value;
        mResolvedPaddingLeft = value;
        mResolvedPaddingRight = value;
    }

    public void setPaddingEnd(int value) {
        mPaddingEnd = value;
    }

    // @TODO: add description
    public void setPaddingLeft(int value) {
        mPaddingLeft = value;
        mResolvedPaddingLeft = value;
    }

    // @TODO: add description
    public void applyRtl(boolean isRtl) {
        if (mPaddingStart > 0 || mPaddingEnd > 0) {
            if (isRtl) {
                mResolvedPaddingLeft = mPaddingEnd;
                mResolvedPaddingRight = mPaddingStart;
            } else {
                mResolvedPaddingLeft = mPaddingStart;
                mResolvedPaddingRight = mPaddingEnd;
            }
        }
    }

    public void setPaddingTop(int value) {
        mPaddingTop = value;
    }

    // @TODO: add description
    public void setPaddingRight(int value) {
        mPaddingRight = value;
        mResolvedPaddingRight = value;
    }

    public void setPaddingBottom(int value) {
        mPaddingBottom = value;
    }

    public int getPaddingTop() {
        return mPaddingTop;
    }

    public int getPaddingBottom() {
        return mPaddingBottom;
    }

    public int getPaddingLeft() {
        return mResolvedPaddingLeft;
    }

    public int getPaddingRight() {
        return mResolvedPaddingRight;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////
    // Solver callback
    /////////////////////////////////////////////////////////////////////////////////////////////

    protected void needsCallbackFromSolver(boolean value) {
        mNeedsCallFromSolver = value;
    }

    // @TODO: add description
    public boolean needSolverPass() {
        return mNeedsCallFromSolver;
    }

    /////////////////////////////////////////////////////////////////////////////////////////////
    // Measure
    /////////////////////////////////////////////////////////////////////////////////////////////

    // @TODO: add description
    public void measure(int widthMode, int widthSize, int heightMode, int heightSize) {
        // nothing
    }

    @Override
    public void updateConstraints(ConstraintWidgetContainer container) {
        captureWidgets();
    }

    // @TODO: add description
    public void captureWidgets() {
        for (int i = 0; i < mWidgetsCount; i++) {
            ConstraintWidget widget = mWidgets[i];
            if (widget != null) {
                widget.setInVirtualLayout(true);
            }
        }
    }

    public int getMeasuredWidth() {
        return mMeasuredWidth;
    }

    public int getMeasuredHeight() {
        return mMeasuredHeight;
    }

    // @TODO: add description
    public void setMeasure(int width, int height) {
        mMeasuredWidth = width;
        mMeasuredHeight = height;
    }

    protected boolean measureChildren() {
        BasicMeasure.Measurer measurer = null;
        if (mParent != null) {
            measurer = ((ConstraintWidgetContainer) mParent).getMeasurer();
        }
        if (measurer == null) {
            return false;
        }

        for (int i = 0; i < mWidgetsCount; i++) {
            ConstraintWidget widget = mWidgets[i];
            if (widget == null) {
                continue;
            }

            if (widget instanceof Guideline) {
                continue;
            }

            DimensionBehaviour widthBehavior = widget.getDimensionBehaviour(HORIZONTAL);
            DimensionBehaviour heightBehavior = widget.getDimensionBehaviour(VERTICAL);

            boolean skip = widthBehavior == DimensionBehaviour.MATCH_CONSTRAINT
                    && widget.mMatchConstraintDefaultWidth != MATCH_CONSTRAINT_WRAP
                    && heightBehavior == DimensionBehaviour.MATCH_CONSTRAINT
                    && widget.mMatchConstraintDefaultHeight != MATCH_CONSTRAINT_WRAP;

            if (skip) {
                // we don't need to measure here as the dimension of the widget
                // will be completely computed by the solver.
                continue;
            }

            if (widthBehavior == DimensionBehaviour.MATCH_CONSTRAINT) {
                widthBehavior = DimensionBehaviour.WRAP_CONTENT;
            }
            if (heightBehavior == DimensionBehaviour.MATCH_CONSTRAINT) {
                heightBehavior = DimensionBehaviour.WRAP_CONTENT;
            }
            mMeasure.horizontalBehavior = widthBehavior;
            mMeasure.verticalBehavior = heightBehavior;
            mMeasure.horizontalDimension = widget.getWidth();
            mMeasure.verticalDimension = widget.getHeight();
            measurer.measure(widget, mMeasure);
            widget.setWidth(mMeasure.measuredWidth);
            widget.setHeight(mMeasure.measuredHeight);
            widget.setBaselineDistance(mMeasure.measuredBaseline);
        }
        return true;
    }

    BasicMeasure.Measurer mMeasurer = null;

    protected void measure(ConstraintWidget widget,
            ConstraintWidget.DimensionBehaviour horizontalBehavior,
            int horizontalDimension,
            ConstraintWidget.DimensionBehaviour verticalBehavior,
            int verticalDimension) {
        while (mMeasurer == null && getParent() != null) {
            ConstraintWidgetContainer parent = (ConstraintWidgetContainer) getParent();
            mMeasurer = parent.getMeasurer();
        }
        mMeasure.horizontalBehavior = horizontalBehavior;
        mMeasure.verticalBehavior = verticalBehavior;
        mMeasure.horizontalDimension = horizontalDimension;
        mMeasure.verticalDimension = verticalDimension;
        mMeasurer.measure(widget, mMeasure);
        widget.setWidth(mMeasure.measuredWidth);
        widget.setHeight(mMeasure.measuredHeight);
        widget.setHasBaseline(mMeasure.measuredHasBaseline);
        widget.setBaselineDistance(mMeasure.measuredBaseline);
    }

    // @TODO: add description
    public boolean contains(HashSet<ConstraintWidget> widgets) {
        for (int i = 0; i < mWidgetsCount; i++) {
            ConstraintWidget widget = mWidgets[i];
            if (widgets.contains(widget)) {
                return true;
            }
        }
        return false;
    }
}