Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnimatorSet with setStartDelay call to onAnimationStart

I'm using android KitKat and this seems to be not working as expected. I have an AnimatiorSet which should start after some delay but I want to make some action when the animation actually starts (after the delay). It seems that AnimatorSet invokes onAnimationStarted on listeners immediately after calling start().

Sample code below:

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

In this case the listener is invoked immediately instead of delayed. To work around this issue I checked if adding the listener to the animators passed into playTogether gives the expected result and it actually does. Is this a bug?

like image 225
serine Avatar asked Apr 15 '14 12:04

serine


1 Answers

Another workaround for that is:

@Override
public void onAnimationStart(Animator animator) {
    rootView.postDelayed(new Runnable() {
        @Override
        public void run() {
            // todo
        }
    }, set.getStartDelay());
}
like image 187
semsamot Avatar answered Sep 30 '22 04:09

semsamot