自定义动画的动画侦听器

问题描述 投票:7回答:1

我使用fragmentTansaction.setCustomAnimation(in,out)为片段事务设置了自定义动画。我想知道动画的开始和结束并触发一些相应的动作。我怎样才能做到这一点?是否可以设置一些列表器?

android animation android-animation fragment
1个回答
0
投票

您可以在onStart()中使用动画来获取getDecorView()

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

        if (getDialog().getWindow().getDecorView()) {
            ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(getDialog().getWindow().getDecorView(),
                    PropertyValuesHolder.ofFloat(View.Y, 0, 1000));
            objectAnimator.setDuration(1000);
            objectAnimator.addListener(new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {

                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
            objectAnimator.start();
        }

    }
© www.soinside.com 2019 - 2024. All rights reserved.