andkulikov / Transitions-Everywhere

Set of extra Transitions on top of Jetpack Transitions Library
Apache License 2.0
4.83k stars 486 forks source link

Endless smooth 360° rotation animation? #64

Closed MehdiFal closed 7 years ago

MehdiFal commented 7 years ago

Hi,

Great library!

I'm working on a 360° animation where a layout processArc should keep endlessly rotating on the same direction. Now I have achieved the 'continuous' part of the rotation, the issue I face is a little deceleration and small stop at the end of every rotation cycle.

Here is my code:

private long rotationAngle;
private TransitionListener transitionListener;

@Override
protected void onCreate (Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);
    setContentView (R.layout.activity);
    // ...
    transitionListener = new SimpleTransitionListener () {

        @Override
    public void onTransitionEnd (Transition transition) {
            animateProcessingAction (null);
    }
    };
}

public void animateProcessingAction (View view) {   
    rotationAngle += 360;

    TransitionManager.beginDelayedTransition (
        processContainer,
    new Rotate ()
        .setDuration (2000)
        .removeListener (transitionListener)
        .addListener (transitionListener)
    );

    processArc.setRotation (rotationAngle);
}

How can I fix that?

Thank you!

andkulikov commented 7 years ago

Hi.

Transitions is not about endless animation. It is about animating some change only once.

And about your requirement, the easiest solution is RotateAnimation rotate = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(2000); rotate.setInterpolator(new LinearInterpolator()); view.startAnimation(rotate);

MehdiFal commented 7 years ago

Hey @andkulikov

Wow that was fast, Thanks for your response!

Understood.

I already implemented it, I just thought I could leverage Transitions-Everywhere to stay consistent with the rest of the code using it.

Thanks again :)