0

I have a motion layout and I want to when animation ended, Start another activity. So I have two problems:

  1. I create this Description file for motion layout:

<Transition
    android:id="@+id/starttoend"
    motion:constraintSetEnd="@+id/end"
    motion:constraintSetStart="@id/start"
    motion:duration="800" />

<Transition
    android:id="@+id/deley"
    motion:constraintSetEnd="@+id/deleyLayout"
    motion:constraintSetStart="@+id/end"
    motion:duration="800" />

<ConstraintSet android:id="@+id/start">
    <Constraint
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/_80sdp"
        android:rotation="120"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
    <Constraint
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        android:rotation="0"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/deleyLayout">
    <Constraint
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        motion:layout_constraintBottom_toBottomOf="parent"
        motion:layout_constraintEnd_toEndOf="parent"
        motion:layout_constraintStart_toStartOf="parent"
        motion:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

This code animates an image view and then wait for 800ms. My problem is when I set motion_layout.transitionToEnd() to activity, Animation not starting.

  1. When I use motion:autoTransition="animateToEnd" attribute in Transition Tag, And set a listener to motion layout for use Intent, Activity will be black and not show anything and then launch intent activity. And in my Log I have two "Done":

         motion_splash.addTransitionListener(object : MotionLayout.TransitionListener {
         override fun onTransitionStarted(p0: MotionLayout?, p1: Int, p2: Int) {
         }
         override fun onTransitionChange(
             p0: MotionLayout?, p1: Int, p2: Int, p3: Float
         ) {
         }
         override fun onTransitionCompleted(p0: MotionLayout?, p1: Int) {
             Log.i("completed" , "Done")
             startActivity(Intent(this@SplashScreenActivity, MainActivity::class.java))
             finish()
         }
         override fun onTransitionTrigger(
             p0: MotionLayout?, p1: Int, p2: Boolean, p3: Float) {
         }
     })
    

Can you help me, please?!

Marlen Schreiner
  • 726
  • 10
  • 25

2 Answers2

0

test p1 == R.id.end to make sure you have completed you transition.

Make sure you are running ConstraintLayout2.0.1

hoford
  • 4,918
  • 2
  • 19
  • 19
0

If you see done twice, it means your transition was called twice probably on a layout pass when the screen was not ready.

Please move initialization code to onResume or wherever its meant to start and ensure that this is done after onResume. The TransitionListener must be added in onCreate()

D Lad
  • 146
  • 8