Hero Transitions not working Android Lollipop

不羁的心 提交于 2019-12-13 05:21:44

问题


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.


回答1:


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">
...


来源:https://stackoverflow.com/questions/26616127/hero-transitions-not-working-android-lollipop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!