Search code examples
androidshared-element-transitionactivity-transition

Hero Transitions not working Android Lollipop


I tried to make animations/transitions between activities but I couldn't make it perfect and good. And I couldn't find any helping guide. Can you tell me how to create an ActivityOptions tranistion, like this: http://3.bp.blogspot.com/-dadidlU3muU/VE6og4Ra_BI/AAAAAAAAA8E/uVCWrYMetGI/s400/herotransition.gif

Step by step? Thanks.


Solution

  • You need two shared elements:

    1. The card (the entire card) from the list view will be shared and mapped to the root view of the detail view activity. You can transition that with a ChangeBounds.
    2. The ImageView from the list view will be shared and mapped to the ImageView in the detail view activity. You can use a TransitionSet with both ChangeBounds and ChangeImageTransform.

    That means that your activity options will look something like this:

    ActivityOptions.makeSceneTransition(YourActivity.this, Pair.create(yourCardViewInstance, "cardView"), Pair.create(yourImageViewInstance, "imageView")
    

    Finally, make sure that the views in your second activity have transition names that match those in your ActivityOptions. E.g.

    <FrameLayout
        android:transitionName="cardView">
        <ImageView
          android:transitionName="ImageView">
    ...