I believe you'll need to manually update the ConstraintLayout
.
I don't know exactly how you have your views, so i'll just create an example.
In the XML, we have the initial position of the image view (imagine it's parent is a constraint layout):
android:id="@+id/image_view"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_marginRight="20dp"
When then it comes to moving the image view, you would manually update the constraints, in this case, the right margin (to move it left):
val constraintLayout: ConstraintLayout = findViewById(R.id.constraint_layout)
val constraintSet = ConstraintSet()
constraintSet.clone(constraintLayout)
constraintSet.clear(R.id.image_view, ConstraintSet.RIGHT);
constraintSet.connect(R.id.image_view, ConstraintSet.RIGHT, R.id.constraint_layout, ConstraintSet.RIGHT, 40)
constraintSet.applyTo(constraintLayout)
Updating the constraints seems a bit long winded but unfortunately that's just how they work (you make a copy or create a whole new set of constraints and apply it to the view).
In this example, you'd changing the right margin from 20dp to 40dp, shifting the image view right by 20dp instantly with no animation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…