I have an activity launched with a scene transition with a shared element, and it works properly.
ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), sharedView, "sharedView");
Intent intent = new Intent(getActivity(), NewActivity.class);
ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
The element is animated smoothly from the old to the new activity. However, I'd like to change how the transition animates a bit, particularly the interpolator. It seems to be using the default smooth interpolator, but I'd like to use the new Material fast-out-slow-in interpolator, and I can't figure out how to specify that.
What should I do to override the default transition?
In case you haven't figured it out yet:
Create a new transitionSet
in your /res/transition/
, define your transition tags with their properties and interpolators, then apply it to your activity style in /res/values-v21/styles.xml
Create a new_activity_transition.xml
inside /res/transition/
which contains the following example transition tags and their interpolators:
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeImageTransform
android:interpolator="@android:interpolator/fast_out_slow_in"
/>
<arcMotion
android:interpolator="@android:interpolator/fast_out_slow_in"/>
<changeBounds
android:duration="300"
android:interpolator="@android:interpolator/fast_out_slow_in"/>
</transitionSet>
Then set it as the shared element enter transition in your /res/values-v21/styles.xml
:
<style name="NewActivity">
<item name="android:windowSharedElementEnterTransition">@transition/new_activity_transition</item>
</style>
Don't forget to set the activity theme in your AndroidManifest.xml
:
<activity
android:name="{path to}.NewActivity"
android:theme="@style/NewActivity">
</activity>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With