asyl/ArcAnimator

Preparing and starting animation separately

aashreys opened this issue · 1 comments

Hey,

I want to use the ArcAnimator library in my app for animating a fab button. However I am unable to set it up the way I like it.

In my code I use the ArcAnimator as follows but it does not work.

private ArcAnimator animation;

public void prepareAnim() {
animation = ArcAnimator.createArcAnimator(
fab,
x,
y,
FAB_ANIM_ANGLE,
FAB_ANIM_SIDE
);
animation.setDuration(FAB_ANIM_DURATION);
}

public void runAnim() {
animation.start();
}

@OverRide
protected void onCreate() {
......
prepareAnim();
Button button = ......;
button.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View
runAnim();
}
});
}

....

}

This does not seem to work. I do not want to setup the animation and then immediately run it when I press the button because it causes a small delay in the animation on older devices. So instead I'm setting up the animation before hand.

Can you please help me out understand how I can get this to work?

Sent from Mailbird

asyl commented

Try this in your OnCreate() method after findViewById()

button.getViewTreeObserver().addOnGlobalLayoutListener(
        new ViewTreeObserver.OnGlobalLayoutListener() {
          @Override
          public void onGlobalLayout() {
            prepareAnim();
            button.getViewTreeObserver().removeGlobalOnLayoutListener(this);
          }
        });