ConstraintLayout 在代码中动态设置约束
ConstraintLayout 在代码中动态设置约束
ConstraintLayout的普及让Android的开发者们能更方便地进行布局,但如何在代码中设置ConstraintLayout的约束呢?网上的资料不太详细,在这里归纳总结一下。
ConstraintSet
这个类在官方文档上是这样描述的:
This class allows you to define programmatically a set of constraints
to be used with ConstraintLayout.For details about Constraint behaviour see ConstraintLayout. It lets
you create and save constraints, and apply them to an existing
ConstraintLayout. ConstraintsSet can be created in various ways:
Manually
c = new ConstraintSet(); c.connect(…);from a R.layout.* object
c.clone(context, R.layout.layout1);