Open In App
Related Articles

Bounce Animation in Android

Like Article
Save Article
Report issue

To make the android app more attractive we add many things and animation is one of the best things which makes the app more attractive and engages the user with the app. So in this article, we will add a bounce animation to the Button. One can use this tutorial to add Bounce animation to any View in android studio such as ImageView, TextView, EditText, etc. A sample GIF is given below to get an idea about what we are going to do in this article.

bounce animation

Steps for Creating Bounce Animation

Step 1: Creating a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that choose Java as language though we are going to implement this project in Java language.

Step 2: Designing the UI 

  • Go to the app -> res right click on res folder then New -> Android Resource Directory and create an anim Directory.
  • Then right-click on anim folder then go to New -> Animation Resource File and create a bounce.xml file.
  • bounce.xml file contains the animation which is used to animate the Button in the next step. The complete code for bounce.xml is given below.


<?xml version="1.0" encoding="utf-8"?>


  • Now Go to the app -> res -> layout -> activity_main.xml file and add a simple Button, which we want to animate. Here is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
<!-- Button with Bounce Animation -->
    android:text="Let's Bounce"


Step 3: Working with file

  • Open the call and inside the onCreate() method get the animation from the anim folder.

// loading Animation from

final Animation animation = AnimationUtils.loadAnimation(this,R.anim.bounce);

  • Get the reference of the Button which we created in the activity_main.xml file

// getting the Button from activity_main.xml file

final Button button= findViewById(;

  • Create an OnClickListener for the Button and startAnimation inside onClick().

// clickListener for Button

button.setOnClickListener(new View.OnClickListener() {


           public void onClick(View view) {

              // start the animation




  • The complete code for the file is given below.

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // loading Animation from
        final Animation animation = AnimationUtils.loadAnimation(this, R.anim.bounce);
        // getting the Button from activity_main.xml file
        final Button button = findViewById(;
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                // start the animation


Output: Run on Emulator 


Last Updated : 23 Feb, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads