Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android scene transition: Custom interpolator?

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?

like image 289
Steven Schoen Avatar asked Apr 25 '15 17:04

Steven Schoen


1 Answers

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

Example for your NewActivity

  • 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>
    
like image 51
papageorgiouk Avatar answered Sep 28 '22 07:09

papageorgiouk