【问题标题】:Android | Non-stop transition form an animation to an animatorSet安卓 |从动画到 animatorSet 的不间断过渡
【发布时间】:2014-12-15 01:14:27
【问题描述】:

我正在尝试制作一个组合动画,其中首先移动视图 (TranslateAnimation),然后隐藏/显示 (createCircularReveal Animator)(like here)。现在,我通过使用 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

【问题讨论】:

  • 能够看到您的代码可能会有所帮助

标签: android animation


【解决方案1】:

你可以试试这个:

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);

【讨论】:

  • 你不能在 AnimationSet 中添加 Animator,对吗?
  • @SnafuBernd 它在编译时没有给出错误(我已经尝试过了),但我不确定它在运行时会做什么......试试吧:)
  • @SnafuBernd 好吧,那是我的错。无论如何..请将您的代码添加到您的问题中
  • 好吧,有趣的是,我通过动画延迟完成了它,但是我在两行代码中分别启动了 Animator 和 Animation。并将延迟设置为 300,而第一个动画需要 500,但现在看起来动画师在动画之后立即开始。我将此标记为答案,因为延迟是解决问题的方法。
猜你喜欢
  • 1970-01-01
  • 2015-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-18
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多