val margin = 8
ConstraintSet().apply {
connect(anId, ConstraintSet.START, anotherId, ConstraintSet.START, margin)
}
Is margin applied as pixels or density-dependent pixels?
Various articles scattered around the web and apocryphal knowledge seem not to agree on one or the other. I'm looking for official documentation or source evidence.
The
marginparameter should be supplied in pixels.I ended up tracing the
ConstraintSet.applyTo(ConstraintLayout)down toConstraintSet.applyToInternal(ConstraintLayout)and found that here, each child of aConstraintLayouthas itsLayoutParamscopied and passed toConstraintSet.Constraint.applyTo(LayoutParams). Which then copies all the parameters (without modification) from theConstraintSet.Constraintinto theLayoutParamsand then assigns the modifiedLayoutParamsback to the child. I think this is concrete evidence that the supplied margin parameters should follow theLayoutParamsrules.in ConstraintSet.java
at
applyToInternal(ConstraintLayout)declarationat
applyTo(LayoutParams)declaration