Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

XML to JSON and DSL for ConstraintSet attributes

Shane Wong edited this page Oct 12, 2022 · 23 revisions

XML for ConstraintSet has many attributes because of the way XML works. Many of them have been combined for example android:layout_width, layout_constraintWidth, layout_constrainedWidth, layout_constraintWidth_min, layout_constraintWidth_max, layout_constraintWidth_percent, and layout_constraintDimensionRatio are all combined in width:

{
  width: 23,
  width: 'spread',
  width: { value: 'wrap', max: 300 }
}
XML JSON DSL Example
android:orientation 1*
android:id 2* createRefFor(...)
android:visibility visibility visibility = Visibility.kt (DSL)
test.kt (JSON)
visibilityMode N/A
android:alpha alpha alpha = Visibility.kt (DSL)
test.kt (JSON)
android:rotation rotationZ rotationZ = Transforms.kt (DSL)
test.kt (JSON)
android:rotationX rotationX rotationX = Transforms.kt (DSL)
VTest02.kt (JSON)
android:rotationY rotationY rotationY = MotionCarouselDemos.kt (DSL)
VTest02.kt (JSON)
android:scaleX scaleX scaleX = CollapsibleToolbar.kt (DSL)
test.kt (JSON)
android:scaleY scaleY scaleY = CollapsibleToolbar.kt (DSL)
test.kt (JSON)
pivotAnchor TBD
android:transformPivotX pivotX pivotX = Transforms.kt (DSL)
test.kt (JSON)
android:transformPivotY pivotY pivotY = MISSING (DSL)
test.kt (JSON)
transformPivotTarget TBD
android:translationX translationX translationX = Transforms.kt (DSL)
test.kt (JSON)
android:translationY translationY translationY = Transforms.kt (DSL)
CyclesDemo.kt (JSON)
android:translationZ translationZ translationZ = Transforms.kt (DSL)
test.kt (JSON)
android:elevation translationZ elevation = MotionStatesExample.kt (DSL)
test.kt (JSON)
android:layout_width (?) width (?) Modifier.width()
Modifier.fillMaxWidth()
Modifier.fillMaxSize()
AttributesDemo.kt (DSL)
N/A (JSON)
android:layout_height (?) height (?) Modifier.height()
Modifier.fillMaxHeight()
Modifier.fillMaxSize()
AttributesDemo.kt (DSL)
N/A (JSON)
layout_constraintWidth Deprecated Deprecated
layout_constraintHeight Deprecated Deprecated
android:layout_marginStart start start.linkTo() Chains.kt (DSL)
test.kt (JSON)
android:layout_marginBottom bottom bottom.linkTo() Chains.kt (DSL)
test.kt (JSON)
android:layout_marginTop top top.linkTo() Chains.kt (DSL)
test.kt (JSON)
android:layout_marginEnd end end.linkTo() Chains.kt (DSL)
test.kt (JSON)
android:layout_marginLeft left left.linkTo() BarrierTest01.kt (JSON)
android:layout_marginRight right right.linkTo() BarrierTest01.kt (JSON)
layout_constraintCircle circular circular() test4.kt (DSL)
test.kt (JSON)
layout_constraintCircleRadius circular circular() test4.kt (DSL)
test.kt (JSON)
layout_constraintCircleAngle circular circular() test4.kt (DSL)
test.kt (JSON)
layout_constraintGuide_begin type: 'h/vGuideline' createGuidelineFromStart()
createGuidelineFromTop()
createGuidelineFromAbsoluteLeft()
test.kt (DSL)
VTest.kt (JSON)
layout_constraintGuide_end type: 'h/vGuideline' createGuidelineFromEnd()
createGuidelineFromBottom()
createGuidelineFromAbsoluteRight()
test.kt (DSL)
VTest.kt (JSON)
layout_constraintGuide_percent type: 'h/vGuideline' createGuidelineFromStart()
createGuidelineFromTop()
createGuidelineFromAbsoluteLeft()
createGuidelineFromEnd()
createGuidelineFromBottom()
createGuidelineFromAbsoluteRight()
Guidelines.kt (DSL)
DslTest.java (JSON)
layout_constraintLeft_toLeftOf left absoluteLeft.linkTo() (?) rtl.kt (DSL)
VTest02.kt (JSON)
layout_constraintLeft_toRightOf left absoluteLeft.linkTo() (?) MISSING (DSL)
FlowDemo.kt (JSON)
layout_constraintRight_toRightOf left absoluteRight.linkTo() (?) MISSING (DSL)
VTest02.kt (JSON)
layout_constraintRight_toLeftOf left absoluteRight.linkTo() (?) MISSING (DSL)
MISSING (JSON)
layout_constraintTop_toTopOf top top.linkTo() test.kt (DSL)
test.kt (JSON)
layout_constraintTop_toBottomOf top top.linkTo() test.kt (DSL)
test.kt (JSON)
layout_constraintBottom_toTopOf bottom bottom.linkTo() test.kt (DSL)
test.kt (JSON)
layout_constraintBottom_toBottomOf bottom bottom.linkTo() test.kt (DSL)
test.kt (JSON)
layout_constraintBaseline_toBaselineOf baseline baseline.linkTo() MotionModifierListDemo.kt (DSL)
MISSING (JSON)
layout_constraintBaseline_toTopOf baseline baseline.linkTo() MISSING (DSL)
VTest02.kt (JSON)
layout_constraintBaseline_toBottomOf baseline baseline.linkTo() MISSING (DSL)
MISSING (JSON)
layout_constraintStart_toEndOf start start.linkTo() MotionModifierListDemo.kt (DSL)
MotionComposeExamples.kt (JSON)
layout_constraintStart_toStartOf start start.linkTo() MotionModifierListDemo.kt (DSL)
MotionComposeExamples.kt (JSON)
layout_constraintEnd_toStartOf end end.linkTo() MotionModifierListDemo.kt (DSL)
MotionComposeExamples.kt (JSON)
layout_constraintEnd_toEndOf end end.linkTo() MotionModifierListDemo.kt (DSL)
MotionComposeExamples.kt (JSON)
layout_goneMarginLeft left left.linkTo()* MISSING (DSL)
test.kt (JSON)
layout_goneMarginTop top top.linkTo()* Chains.kt (DSL)
DslTest.java (JSON)
layout_goneMarginRight right right.linkTo()* MISSING (DSL)
DslTest.java (JSON)
layout_goneMarginBottom bottom bottom.linkTo()* Chains.kt (DSL)
DslTest.java (JSON)
layout_goneMarginStart start start.linkTo()* Chains.kt (DSL)
DslTest.java (JSON)
layout_goneMarginEnd end end.linkTo()* Chains.kt (DSL)
test.kt (JSON)
layout_goneMarginBaseline baseline baseline.linkTo()* MISSING (DSL)
MISSING (JSON)
layout_marginBaseline baseline baseline.linkTo()* MISSING (DSL)
VTest02.kt (JSON)
layout_constrainedWidth width width = (DSL)
(JSON)
layout_constrainedHeight height height = (DSL)
(JSON)
layout_constraintHorizontal_bias hBias linkTo() (DSL)
(JSON)
layout_constraintVertical_bias vBias linkTo() (DSL)
(JSON)
layout_constraintWidth_default width width = (DSL)
(JSON)
layout_constraintHeight_default height height = (DSL)
(JSON)
layout_constraintWidth_min (?) width width = Dimension.fillToConstraints.atLeast() (DSL)
VTest02.kt
(JSON)
layout_constraintWidth_max (?) width width = Dimension.fillToConstraints.atMost() Dimensions.kt (DSL)
(JSON)
layout_constraintWidth_percent width width = (DSL)
VTest02.kt (JSON)
layout_constraintHeight_min (? height height = Dimension.fillToConstraints.atLeast() (DSL)
MISSING (JSON)
layout_constraintHeight_max (?) height height = Dimension.fillToConstraints.atMost() Dimensions.kt (DSL)
MISSING (JSON)
layout_constraintHeight_percent height height = (DSL)
(JSON)
layout_constraintDimensionRatio height/width width = Dimension.value(100.dp)
height = Dimension.ratio("x:y")
Ratio.kt (DSL)
layout_constraintHorizontal_weight ??? horizontalChainWeight = Chains.kt (DSL)
(JSON)
layout_constraintVertical_weight ??? verticalChainWeight = Chains.kt (DSL)
(JSON)
layout_constraintHorizontal_chainStyle type: 'hChain' createHorizontalChain() Chains.kt (DSL)
DslTest.java (JSON)
layout_constraintVertical_chainStyle type: 'vChain' createVerticalChain() Chains.kt (DSL)
DslTest.java (JSON)
layout_wrapBehaviorInParent ???
barrierDirection v/hBarrier* createStartBarrier()
createAbsoluteLeftBarrier()
createTopBarrier()
createEndBarrier()
createAbsoluteRightBarrier()
createBottomBarrier()
Barriers.kt (DSL)
Barriers.kt (JSON)
barrierAllowsGoneWidgets v/hBarrier* createStartBarrier*
flow_wrapMode wrap wrapMode = FlowDslDemo.kt (DSL)
FlowDemo2.kt (JSON)
orientation (Flow) type flowVertically = FlowDslDemo.kt (DSL)
FlowDemo2.kt (JSON)
flow_horizontalStyle hStyle horizontalStyle = FlowDslDemo.kt (DSL)
FlowDemo2.k (JSON)
flow_firstHorizontalStyle hStyle horizontalStyle = [first, middle, last] FlowDemo2.kt (JSON)
flow_lastHorizontalStyle hStyle horizontalStyle = [first, middle, last] FlowDemo2.kt (JSON)
flow_verticalStyle vStyle verticalStyle = FlowDslDemo.kt (DSL)
FlowDemo2.kt (JSON)
flow_firstVerticalStyle vStyle verticalStyle = [first, middle, last] FlowDemo2.kt (JSON)
flow_lastVerticalStyle vStyle verticalStyle = [first, middle, last] FlowDemo2.kt (JSON)
flow_horizontalBias hBias/hFlowBias horizontalFlowBias = FlowDslDemo.kt (DSL)
FlowDemo2.kt (JSON)
flow_verticalBias vBias/vFlowBias verticalFlowBias = FlowDslDemo.kt (DSL)
FlowDemo2.kt (JSON)
flow_horizontalGap hGap horizontalGap = FlowDslDemo.kt (DSL)
FlowDemo.kt (JSON)
flow_verticalGap vGap verticalGap = FlowDslDemo.kt (DSL)
FlowDemo.kt (JSON)
flow_horizontalAlign hAlign horizontalAlign = FlowDemo4.kt (JSON)
flow_verticalAlign vAlign verticalAlign = FlowDemo4.kt (JSON)
flow_maxElementsWrap maxElement maxElement = FlowDslDemo.kt (DSL)
FlowDemo4.kt (JSON)
constraint_referenced_ids contains FlowDslDemo.kt (DSL)
FlowDemo.kt (JSON)
constraint_referenced_tags
android:maxHeight height: { max: 300 } (DSL)
(JSON)
android:maxWidth width: { max: 300 } (DSL)
(JSON)
android:minHeight height: { min: 300 } (DSL)
(JSON)
android:minWidth width: { min: 300 } (DSL)
(JSON)
chainUseRtl Not implemented createHorizontalChain()
animateRelativeTo MotionLayout*
animateCircleAngleTo MotionLayout*
transitionEasing MotionLayout*
pathMotionArc MotionLayout*
polarRelativeTo MotionLayout*
transitionPathRotate MotionLayout*
drawPath MotionLayout*
motionProgress Not implemented
layout_constraintTag code only
motionStagger MotionLayout*
quantizeMotionSteps MotionLayout*
quantizeMotionPhase MotionLayout*
quantizeMotionInterpolator MotionLayout*
1* - By convention helpers will be explicitly vertical or horizontal (vBarrier or hBarrier)
2* - The id is usually the label 
MotionLayout* - These features of MotionLayout are not implemented.
Clone this wiki locally