
❓ Ask your programming questions in our chat:

💚 Donate to Coding in Flow with a message: 📨 Subscribe to the Coding in Flow newsletter: 💲 Earn money by becoming an affiliate for my courses: We will also set an AnimationListener on our animation to lock and unlock the spinning method in onAnimationStart and onAnimationEnd. With setDuration we set the length of the animation and with setFillAfter(true) we make sure that the ImageView ends up pointing to the direction at which the rotation ends.

For pivotX and pivotY we will set the middle of the ImageView which we get by dividing getWidth and getHeight by 2. We will get this random direction as a number with the Random class and it's nextInt method.

When we click this image, we start a RotateAnimation which ends at a random direction. We will display the bottle in an ImageView on which we set an onClickListener with the onClick xml attribute. In this video we are going to build a simple spin the bottle game in Android Studio.
