如何以编程方式清除 ConstraintLayout 中的 Widgets(例如 ImageView)约束?

How to clear constraints of Widgets (e.g ImageView) inside ConstraintLayout programmatically?

我到处搜索,How to clear constraints of Widgets inside ConstraintLayout,我找到的一个结果是在stack OverFlow in this link :

但是这个问题的答案在我的情况下不起作用,但是,我的问题是如何以编程方式清除 ConstraintLayout 中的小部件(例如 ImageView)的约束。这是一张说明我要求的图片,谢谢。

创建当前集的克隆,然后对其应用新约束,然后将其应用于视图

ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(R.id.imageView,ConstraintSet.RIGHT,R.id.check_answer1,ConstraintSet.RIGHT,0);
constraintSet.connect(R.id.imageView,ConstraintSet.TOP,R.id.check_answer1,ConstraintSet.TOP,0);
constraintSet.applyTo(constraintLayout);

查看您的 xml 视图约束,找出要清除的约束,我碰巧在使用 START 约束时清除了 LEFT。