Build Blink Animation App in Android

 Hello Guys ,

    In this tutorial , we are going to create blink animation on android app. In this app we create one textview and one button. Button is used to perform blink animation on textview. In this animation text are blink whenever button was clicked. 

and

  Feel free to visit my previous Animation tutorial.

           Zoom Animation

Blink Animation App MainScreen looking like below picture : 



Let's implemented Blink 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. Animation file name is blink.xml.
  • blink.xml 
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha android:fromAlpha="0"
android:toAlpha="1"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"
android:repeatMode="reverse"
android:repeatCount="5"/>


</set>
  • android:fromAlpha : It is used to specify starting value for alpha offset. Where 0.0 is transparent and 1.0 is opaque.
  • android:toAlpha : It is used to specify ending value of alpha offset.
  • android:duration : It is used to specify  duration for animation. 
  • android:repeatMode : It is used to define how to animation behave.
  • android:repeatCount : It is used to define how many times animation is repeat.

Step 3 : Edit activity_main.xml file
  • Here we added button and textview for perform blink animation.
<?xml version="1.0" encoding="utf-8"?>
<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:text="Ps_Inf0"
android:textAllCaps="false"
android:layout_centerInParent="true"
android:textSize="30sp"
android:textColor="@color/design_default_color_secondary"/>


<Button
android:id="@+id/btn_blink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:textAllCaps="false"
android:layout_marginBottom="80dp"
android:text="Blink" />


</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.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

Button blink;
TextView textView;

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

blink = findViewById(R.id.btn_blink);
textView = findViewById(R.id.text);

blink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation animation = AnimationUtils.loadAnimation(
getApplicationContext() , R.anim.blink);
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

1 Comments