Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know when Shared Element Transition ends

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 that I can show other things.

I tried using onSharedElementEnd in SharedElementCallback in the activity I am transition to but that gets called before the transition starts.

is there another callback i can listen for?

like image 366
tyczj Avatar asked Nov 10 '15 23:11

tyczj


People also ask

Which of the following transitions is a shared elements transition?

Android also supports these shared elements transitions: changeBounds - Animates the changes in layout bounds of target views. changeClipBounds - Animates the changes in clip bounds of target views. changeTransform - Animates the changes in scale and rotation of target views.


3 Answers

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<String> names, Map<String, View> 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);
           }
      });
like image 101
Nikola Despotoski Avatar answered Oct 19 '22 19:10

Nikola Despotoski


Please try onEnterAnimationComplete() callback on your activity.

I bet this is exactly what you ere looking for.

 @Override
    public void onEnterAnimationComplete() {
        super.onEnterAnimationComplete();

    //your code 
    }
like image 20
Alex Wih Avatar answered Oct 19 '22 20:10

Alex Wih


Here is what I do in a fragment:

Transition sharedElementEnterTransition = getActivity().getWindow().getSharedElementEnterTransition();
    sharedElementEnterTransition.addListener(new Transition.TransitionListener() {
        @Override
        public void onTransitionStart(Transition transition) {

        }

        @Override
        public void onTransitionEnd(Transition transition) {

        }

        @Override
        public void onTransitionCancel(Transition transition) {

        }

        @Override
        public void onTransitionPause(Transition transition) {

        }

        @Override
        public void onTransitionResume(Transition transition) {

        }
    });
like image 9
Kai Wang Avatar answered Oct 19 '22 20:10

Kai Wang