0

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.

Alex Lockwood
  • 83,063
  • 39
  • 206
  • 250
user3184899
  • 3,019
  • 6
  • 30
  • 38
  • did you look here? http://developer.android.com/training/material/animations.html – tyczj Oct 28 '14 at 18:45
  • Yes, but nothing helped. I have added all what I needed and I have transitions, but the ChangeBounds() transition is not working well because the enter to the new activity transition is just opening the app from the edge of the screen rather than resizing the image. @tyczj – user3184899 Oct 28 '14 at 18:57

1 Answers1

2

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">
...
klmprt
  • 651
  • 6
  • 7
  • Thanks. I tried it. The imageView thing worked, but the part with connecting the RelativeLayout to another RelativeLayout using LayoutInflater, I get: "java.lang.IllegalArgumentException: Ghosted views must be parented by a ViewGroup" What is wrong? – user3184899 Oct 31 '14 at 20:23
  • Try wrapping the RelativeLayout in your second activity with another ViewGroup, e.g. ... – klmprt Nov 01 '14 at 15:48