【发布时间】:2016-03-07 13:23:48
【问题描述】:
我需要将以下动画应用到 imageView:
1. alpha (0 -> 1) and scale (0 -> 1) in 500ms
2. pause for 1000ms
3. alpha (1 -> 0) and scale (1 -> 0) in 500ms
在我看来,这三个Animators 可以用AnimatorSet 顺序播放。
我写了这段代码,其中三个块已经清楚地分开了:
ObjectAnimator alpha1 = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f, 1f);
ObjectAnimator scaleX1 = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f);
ObjectAnimator scaleY1 = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f);
AnimatorSet part1 = new AnimatorSet();
part1.setInterpolator(new OvershootInterpolator());
part1.setDuration(500);
part1.playTogether(alpha1, scaleX1, scaleY1);
ObjectAnimator pause = ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f);
pause.setDuration(1000);
ObjectAnimator alpha0 = ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f, 0f);
ObjectAnimator scaleX0 = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 1f, 0f);
ObjectAnimator scaleY0 = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 1f, 0f);
AnimatorSet part2 = new AnimatorSet();
part2.setInterpolator(new AccelerateDecelerateInterpolator());
part2.setDuration(500);
part2.playTogether(alpha0, scaleX0, scaleY0);
在我看来,这段代码很清晰,比有计时器或监听器要好。
主要问题是,有没有一种“PauseAnimator”可以在类似情况下使用? (实际上第二段代码什么都不做,它在 1000 毫秒内将 alpha 从 1 设置为 1)
【问题讨论】:
标签: android animation objectanimator