使用setStartDelay的AnimatorSet调用onAnimationStart

ser*_*ine 12 animation android synchronization

我正在使用Android KitKat,这似乎没有按预期工作.我有一个动画集应该在一段延迟后启动,但我想在动画实际启动时(延迟之后)做一些动作.似乎AnimatorSet在调用start()后立即在侦听器上调用onAnimationStarted.

示例代码如下:

AnimatorSet set = new AnimatorSet();
set.playTogether(
     ObjectAnimator.ofFloat(obj, "x", 10),
     ObjectAnimator.ofFloat(obj, "y", 10));
set.setStartDelay(5000);
set.setDuration(1000)

set.addListener(new AnimatorListenerAdapter()
{
    @Override
    public void onAnimationStart(Animator animation)
    {
        // do sth
    }
});

set.start();
Run Code Online (Sandbox Code Playgroud)

在这种情况下,立即调用侦听器而不是延迟.为了解决这个问题,我检查了向传递给playTogether的动画师添加监听器是否给出了预期的结果,实际上是这样.这是一个错误吗?

sem*_*mot 5

另一个解决方法是:

@Override
public void onAnimationStart(Animator animator) {
    rootView.postDelayed(new Runnable() {
        @Override
        public void run() {
            // todo
        }
    }, set.getStartDelay());
}
Run Code Online (Sandbox Code Playgroud)