Build Bounce Animation App in Android

 Hello Guys ,

    In this tutorial , we are going to create bounce animation on android app. we can make android app more attractive using bounce animation. we will add bounce animation on textview.

    and

  Feel free to visit my previous Animation tutorial.

      Floating Action Button Animation


   Bounce Animation App MainScreen looking like below picture : 






Let's implemented Bounce Animation App.

Step 1 : Create a new Project

Step 2 : Create the animation file.
  • Go to res folder and create a new Android Resource Directory named "anim". And in the anim resource directory create new animation files. Here Animation file name is animation.xml 
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/bounce_interpolator">

<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0.5"
android:toXScale="1.0"
android:fromYScale="0.5"
android:toYScale="1.0"
android:duration="500"/>

</set>

Step 3 : Edit activity_main.xml file
  • Here we added textview for perform bounce animation.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Bounce Animation"
android:textSize="29sp"
android:textColor="@color/teal_700"/>

</RelativeLayout>

Step 4 : Implement MainActivity.java class file.
  • In this class we can load animation class using Animation class.
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView = findViewById(R.id.text);

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

textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textView.startAnimation(animation);

}
});
}
}
  

Output :






If you liked this post do comment ,share and promote the post 🙏 . Please stay with us and support.  🙏   

Post a Comment

0 Comments