Transitioning on the Android scene: custom interpolator?

I have an action running with a scene transition with a common element, and it works correctly.

ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), sharedView, "sharedView"); Intent intent = new Intent(getActivity(), NewActivity.class); ActivityCompat.startActivity(getActivity(), intent, options.toBundle()); 

The element animates smoothly from old to new. However, I would like to change how the transition animates a bit, especially the interpolator. It seems like a smooth default interpolator is being used, but I would like to use a new interpolator with quick material substitution, and I cannot figure out how to indicate this.

What to do to override the default transition?

+6
source share
1 answer

If you haven't figured it out yet:

Create a new transitionSet in /res/transition/ , define transition tags with their properties and interpolators, then apply it to your activity type in /res/values-v21/styles.xml

Example for your NewActivity

  • Create 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 a generic element, enter the transition in /res/values-v21/styles.xml :

     <style name="NewActivity"> <item name="android:windowSharedElementEnterTransition">@transition/new_activity_transition</item> </style> 
  • Remember to set the activity theme in AndroidManifest.xml :

     <activity android:name="{path to}.NewActivity" android:theme="@style/NewActivity"> </activity> 
+4
source

Source: https://habr.com/ru/post/985958/


All Articles