Apply bezier curve to MotionLayout at runtime

I have used this article to create an expand/collapse cardview component. Right now, the expand/collapse animation is linear. I want to apply a bezier curve to the animation so that the animation will be ease-in-out. I have googled a lot and couldn’t find out how it can be added dynamically at runtime. I have seen it applying from the MotionScene xml file. But could not find any material which does this at runtime. Please let me know how this can be added at runtime.
Thanks very much.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Transition has a method setInterpolatorInfo so in the article you reference
where they type transaction.duration = 1000
You should be able to add one of the below.

 val EASE_IN_OUT = 0;
 val EASE_IN = 1;
 val EASE_OUT = 2;
 val LINEAR = 3;
 val BOUNCE = 4;
 val OVERSHOOT = 5;
 val ANTICIPATE = 6;
 //Android Custom Interpolators 
 transaction.setInterpolatorInfo(INTERPOLATOR_REFERENCE_ID , null, R.interpolator.???? )
 // css style string   
 transaction.setInterpolatorInfo(SPLINE_STRING , "cubic(0,0,0,1.0)", 0 )
 // pre baked 
 transaction.setInterpolatorInfo( OVERSHOOT , null, 0 )

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply