Android |从动画到动画集的不间断过渡

时间:2014-12-13 22:59:12

标签: android animation

我正在尝试制作组合动画,其中首先移动视图(TranslateAnimation)然后隐藏/显示(createCircularReveal Animator)(like here)。 Rigth现在,我通过使用onAnimationEnd回调在动画之后启动动画师来完成它。但问题是,它不是立即开始,而是延迟了半秒钟,这使它看起来不那么光滑。

这甚至是做到这一点的正确方法,还是有另一种方法来创建这样的移动+属性动画?

是否可能有一种方法可以调整onAnimationEnd回调,以便真正开始使用它?

编辑:这是我的最终代码:

...
        final Animator circularReveal = ViewAnimationUtils.createCircularReveal(
                ....
        );
        circularReveal.setDuration(3500);
        circularReveal.setInterpolator(new AnimationUtils().loadInterpolator(YourWorkouts.this,
                android.R.interpolator.linear_out_slow_in));
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                createNewWorkoutDialogCardView.setVisibility(View.VISIBLE);
            }
        });

        final Animator circularHide = ViewAnimationUtils.createCircularReveal(
                ...
        );
        circularHide.setDuration(600);
        circularHide.setInterpolator(new AnimationUtils().loadInterpolator(YourWorkouts.this,
                android.R.interpolator.linear_out_slow_in));
        circularHide.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                Log.v("YourWorkouts", "onAnimationEnd: set FAB INVISIBLE");
                createWorkoutFab.setVisibility(View.GONE);
            }
        });

        final AnimatorSet animSet = new AnimatorSet();
        animSet.playTogether(circularHide,circularReveal);
        animSet.setStartDelay(300); // the animator waits only 0.3 seconds 

        Integer fabTranslationDistanceX = fabEndPositionX - (createNewWorkoutFABContainer.getLeft() + createNewWorkoutFABContainer.getWidth()/2);
        Integer fabTranslationDistanceY = fabEndPositionY - createWorkoutFab.getHeight()/2  - (createNewWorkoutFABContainer.getTop() + createNewWorkoutFABContainer.getHeight()/2);
        Log.v("YourWorkouts", "xDialogCenter" + fabTranslationDistanceX);
        TranslateAnimation moveFAB = new TranslateAnimation(0, fabTranslationDistanceX, 0, fabTranslationDistanceY);
        moveFAB.setDuration(500); // the translation takes 0.5 seconds
        moveFAB.setFillAfter(true);
        moveFAB.setInterpolator(new AnimationUtils().loadInterpolator(YourWorkouts.this,
                android.R.interpolator.fast_out_linear_in));

        animSet.start(); // start  animator for property animation
        createNewWorkoutFABContainer.startAnimation(moveFAB); // start animation to move view across the screen

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

anim1将是第一个动画,持续时间为300毫秒,anim2将在300毫秒后启动

TranslateAnimation anim1 = new TranslateAnimation();
Animator anim2 = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);

anim1.setDuration(300);

anim2.setDuration(300);
anim2.setStartOffset(300);