Reputation: 16767
I'm trying to animate constraints change.
My layout is:
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/workspaceOverviewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
tools:visibility="visible">
<View
android:id="@+id/loopScrollLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#990000"
app:layout_constraintBottom_toTopOf="parent"
tools:layout_constraintBottom_toTopOf="@null"
tools:layout_constraintTop_toTopOf="parent" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/workspaceOverviewVp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@id/bottomLayout"
app:layout_constraintTop_toBottomOf="@id/loopScrollLayout" />
<LinearLayout
android:id="@+id/bottomLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="parent"
tools:layout_constraintBottom_toBottomOf="parent"
tools:layout_constraintTop_toBottomOf="@null">
<View
android:id="@+id/indicatorsLayout"
android:layout_width="match_parent"
android:layout_height="16dp"
android:background="#000099" />
<View
android:id="@+id/settingsLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#009900" />
</LinearLayout>
Code is:
val constraintSet = ConstraintSet()
.apply {
clone(workspaceOverviewLayout)
clear(R.id.loopScrollLayout, ConstraintSet.BOTTOM)
clear(R.id.bottomLayout, ConstraintSet.TOP)
connect(R.id.loopScrollLayout, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)
connect(R.id.bottomLayout, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
}
val transition = AutoTransition()
.apply {
duration = overviewAnimationDuration // 10_000L
interpolator = AccelerateInterpolator()
}
TransitionManager.beginDelayedTransition(workspaceOverviewLayout, transition)
constraintSet.applyTo(workspaceOverviewLayout)
Constraints are applied correctly, but just instantly, without any animation.
I use ConstraintLayout 2.0.2
(also tried with 2.0.1
) on Android 10.
Upvotes: 0
Views: 613
Reputation: 16767
Well, the issue was that I was trying to change workspaceOverviewLayout
's visibility and apply the ConstraintSet
right after it.
This two operations should be ran in different layout passes, so to fix it I need just to do this:
private fun enterOverviewMode() {
workspaceOverviewLayout.isVisible = true
workspaceVp.isVisible = false
workspaceOverviewLayout.post { // Post to «delay» the constraint change
animateEnterOverviewMode()
}
Upvotes: 1