Search code examples
androidmaterial-designtransition

Android Material Motion between two activites


i have two Activities (One with a Recyclerview and a DetailsActvity which will be started with startActvityForResult).

Now i want to make an animation like this when i click on a list item.

https://material.io/guidelines/motion/material-motion.html#material-motion-implications-of-motion

it would be great if someone can show me an easy way to realize that.


Solution

  • What you are looking for is called makeSceneTransitionAnimation. It is fairly simple to use, you need to have a shared Element on both screens, which has a common XML Tag "transitionName", e.g.

    "android:transitionName="clock" 
    

    and then start the activity with the makeSceneTransitionAnimation:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                Pair<View, String> p1 = Pair.create(clock, "clock");
    
                ActivityOptionsCompat options = ActivityOptionsCompat.
                        makeSceneTransitionAnimation((Activity) getContext(), p1);
    
                mView.getContext().startActivity(intent, options.toBundle());
    

    }

    Edit: I wrote this before you commented that this is not what you are looking for, though I think you can achieve the shown transition with makeSceneTransitionAnimation.