1

I have two activities: A and B. Both have a ViewPager of images.

There is a shared activity transition with the "current" image as shared element. For example if user scrolls to the third image, the shared element name is image_2.

To execute the transition I just call:

ActivityCompat.startActivityForResult(activity, intent, requestCode,
       ActivityOptionsCompat.makeSceneTransitionAnimation(activity, sharedElements)
             .toBundle());

This works perfectly.

I would like to add a custom exit transition for A (the caller activity). The latter should just fade-out another view.

How can I achieve this goal?

fran
  • 1,119
  • 1
  • 10
  • 27

1 Answers1

0

You can specify the exit, reenter, enter, and return transition using this following method.

getWindow().setEnterTransition(getEnterTransition());
getWindow().setReturnTransition(getReturnTransition());
getWindow().setExitTransition(getExitTransition());
getWindow().setReenterTransition(getReenterTransition());

Of course, in your case you only need to set the exit transition. But the reason why I include this is you probably want to set reenter transition from your caller Activity.

To answer your question (Fade out) you can use Fade transition like this

@SuppressWarnings("NewApi")
private Transition getExitTransition() {
    Fade fadeOut = new Fade(Fade.OUT);
    fadeOut.excludeTarget(android.R.id.navigationBarBackground, true);
    fadeOut.excludeTarget(android.R.id.statusBarBackground, true);
    fadeOut.setInterpolator(new FastOutLinearInInterpolator());
    fadeOut.setDuration(150);
    return fadeOut;
}

You might notice I exclude navigation bar and status bar, it was there to prevent white blinking problem.

There you go, I hope this helps.

Community
  • 1
  • 1
aldok
  • 17,295
  • 5
  • 53
  • 64