How to know when Shared Element Transition ends

后端 未结 5 548
不知归路
不知归路 2020-12-14 15:00

I am working with Shared Element Transitions between activities. The transition is working fine but I want to know when the shared element transition ends so th

5条回答
  •  长情又很酷
    2020-12-14 15:49

    Did you try to bind animation listener to the shared element view inside onMapSharedElements? ViewCompat.animate(view) will give you either a new or cached ViewPropertyAnimator(Compat) and then binding the animation listener should be trivial. I haven't tried it, though.

    setEnterSharedElementCallback(new SharedElementCallback() {
                @Override
                public void onMapSharedElements(List names, Map sharedElements) {
                    super.onMapSharedElements(names, sharedElements);
                    View keySharedElementView = sharedElements.get("keySharedElement");
                    if(keySharedElementView != null){
                        ViewCompat.animate(keySharedElementView).setListener(new ViewPropertyAnimatorListenerAdapter(){
                            @Override
                            public void onAnimationEnd(View view) {
                                super.onAnimationEnd(view);
                            }
                        });
                    }
                }
            });
    

    What about adding Transition.Listener to the shared element transition?

     Transition sharedElementEnterTransition = getWindow().getSharedElementEnterTransition();
     sharedElementEnterTransition.addListener(new TransitionListenerAdapter() {
             @Override
              public void onTransitionEnd(android.support.transition.Transition transition) {
                        super.onTransitionEnd(transition);
               }
          });
    

提交回复
热议问题