如何在爆炸过渡后添加动作

How to add an action after an explode transition

所以我终于想出了如何为回收视图制作爆炸过渡。我想要做的是在过渡完成后更改布局边距。如果我只是在转换启动后添加该行,那是行不通的。那么如何设置一个动作在转换完成后执行呢? 这是代码:

recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                //Set enormous padding
                int prevPreviousBottomPadding = recyclerView.getPaddingBottom();
                int prevPreviousTopPadding = recyclerView.getPaddingTop();
                recyclerView.setPadding(0,2000,0,2000);


                // save rect of view in screen coordinates
                final Rect viewRect = new Rect();
                //v.getGlobalVisibleRect(viewRect);

                //create Explode transition with epicenter
                Transition explode = new Explode();
                explode.setEpicenterCallback(new Transition.EpicenterCallback() {
                    @Override
                    public Rect onGetEpicenter(Transition transition) {
                        return viewRect;
                    }
                });
                explode.setDuration(800);
                TransitionManager.beginDelayedTransition(recyclerView, explode);
                // remove all views from Recycler View
                recyclerView.setAdapter(null);
                
//I need this line to be executed after the transition is completely over.
                recyclerView.setPadding(0,prevPreviousTopPadding,0,prevPreviousBottomPadding);
                return false;
            }
        }); 

想通了!! 在开始动画之前,我们应该添加一个侦听器并覆盖所有必要的方法。这是代码:

   recyclerView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (isAnimating) {
                return false;
            }
            // save rect of view in screen coordinates
            final Rect viewRect = new Rect();
            //v.getGlobalVisibleRect(viewRect);

            //Set enormous padding
            int prevPreviousBottomPadding = recyclerView.getPaddingBottom();
            int prevPreviousTopPadding = recyclerView.getPaddingTop();
            recyclerView.setPadding(0, 2000, 0, 2000);

            //create Explode transition with epicenter
            Transition explode = makeInExplodeTransition();
            explode.setEpicenterCallback(new Transition.EpicenterCallback() {
                @Override
                public Rect onGetEpicenter(Transition transition) {
                    return viewRect;
                }
            });

//Here it is - adding a listener
            explode.addListener(new Transition.TransitionListener() {
                @Override
                public void onTransitionStart(Transition transition) {
                    isAnimating = true;
                }

                @Override
                public void onTransitionEnd(Transition transition) {
                    isAnimating = false;
                    recyclerView.setPadding(0, prevPreviousTopPadding, 0, prevPreviousBottomPadding);
                }

                @Override
                public void onTransitionCancel(Transition transition) {

                }

                @Override
                public void onTransitionPause(Transition transition) {

                }

                @Override
                public void onTransitionResume(Transition transition) {

                }
            });
            TransitionManager.beginDelayedTransition(recyclerView, explode);
            //Deleting everything from our adapter
            recyclerView.setAdapter(null);
            return false;
        }
    });