2
votes

I've got a RecyclerView. When I click on an item, I start a new Activity with Shared Element Transition Animation. In this "child" activity I have a ViewPager and I can move to other items and then press Back. So I need to change the sharedElement-view in the "parent" Activity so that the reverse-transition is applied to the right item.

How can I achieve that? We set sharedElement in makeSceneTransitionAnimation but how to change it for the reverse-animation?

1

1 Answers

0
votes

You have to use SharedElementCallback in First Activity like this:

private final SharedElementCallback exitTransitionCallBack = new SharedElementCallback() {
    @Override
    public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

        sharedElements.clear();
        sharedElements.put("transition name 1", view1);
        sharedElements.put("transition name 2", view2);
    }
};

This code will be executed when you come back from Second Activity to First Activity and vice versa.

And don't forget in onCreate:

setExitSharedElementCallback(exitTransitionCallBack);