Skip to content
xtuzy edited this page Apr 25, 2023 · 7 revisions

Welcome to the SharpConstraintLayout wiki! There have some document about api.

What is FluentConstraintSet/ConstraintSet

ConstraintSet record all descriptions of constraints, these constraints define the relationship between controls. ConstraintLayout according to these constraints to calculate size and position of controls. it's unit use pixel.

FluentConstraintSet supply a fluent api for ConstraintSet. it's unit use dp.

You can only create constraints in code, if you want hotreload, you can create constraints in event like SizeChanged, c# hotreload will load it when size changed of view.

Process of using SharpConstraintLayout

  • use new ConstraintLayout() create ConstraintLayout
  • use AddElement() add control to ConstraintLayout
  • use new FluentConstraintSet() create FluentConstraintSet
    • use Clone() from ConstraintLayout get old constraints and all controls id
    • use Select() select a control, then specify constraints for it, such as LeftToLeft(), if no params, mean left of control align with left of parent
    • use AppplyTo() apply FluentConstraintSet to ConstraintLayout

Key concepts

  • Constraint

LeftToLeft TopToTop RightToRight..., What does these constraint mean? you can imagine it's a spring, constraintset.Select(button1).LeftToLeft(parent) like a spring connect left of button1 with left of parent, it let left of button1 align with left of parent. After set constraintset.Select(button1).(parent), that also have a spring connnect right of button1 with right of parent, so these two springs will let button1 at horizontal center of parent. If you set constraintset.Select(button1).Width(SizeBehavier.MatchConstraint), it will let button1 be stretched by springs.

Clone this wiki locally