Android shared element transition between two activities does not work

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

In my app I'm trying to use the newly introduced element sharing between activities. Everything works like a charm if the shared element is with fixed position (e.g. android:layout_gravity="top") but the problem comes when the view is anchored.

My first activity looks like this:

         ...     

My second activity looks like this

         ...           ...  

The code I use is as follows:

Intent intent = ...; ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, view, "fab_button"); startActivity(intent, options.toBundle()); 

If I use the layout_anchor and layout_anchorGravity attributes the transition between the two FABs is done with no animation. If the second FAB is with fixed position, it works perfectly. What am I doing wrong?

回答1:

This might be a bit late, but I found a way around the issue. You have to wrap your shared element into a layout, and put the anchor on that layout:



回答2:

Activity Shared Elements Transitions:

Follow the steps.

  1. Enable Window Content Transitions
  2. Assign a Common Transition Name
  3. Start Activity
  4. Multiple Shared Elements
  5. Customizing Shared Elements Transition

I think you do not have follow the second step. You had given android:transitionName="fab_button" in Second Activity but not given in First Activity.

XML of First Activity (added android:transitionName="fab_button"):

May above links will helps you.



回答3:

You should have transition name in receiving activity also. Check my code.

First Activity

    

And Second Activity xml



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