Thursday, December 5, 2019

Circle Animation in Android

How to make a smooth image rotation in Android?
 Clockwise rotation 
    public void rorate_Clockwise(View view) {
        ObjectAnimator rotate = ObjectAnimator.ofFloat(view, "rotation", 180f, 0f);
//        rotate.setRepeatCount(10);
        rotate.setDuration(500);
        rotate.start();
    }
 AntiClockwise rotation :
 public void rorate_AntiClockwise(View view) {
        ObjectAnimator rotate = ObjectAnimator.ofFloat(view, "rotation", 0f, 180f);
//        rotate.setRepeatCount(10);
        rotate.setDuration(500);
        rotate.start();
    } 
The view is the object of your ImageView or other widgets.
rotate.setRepeatCount(10); use to repeat your rotation.
500 is your animation time duration.
If you implemented AnimatorListener in your MainActivity, you must include all its abstract methods and change nAnim.addListener(new Animat.... to nAnim.addListener(this)
@Override
public void onAnimationStart(Animator animation){
}

@Override
public void onAnimationEnd(Animator animation){
    startGame(level)
}

@Override
public void onAnimationRepeat(Animator animation){
}

@Override
public void onAnimationCancel(Animator animation){
}

No comments:

Post a Comment