Blink imageview image in android

In this tutorial we will see a simple animation to an imageview which allows the imageview to blink in certain duration. Let us start by adding imageview to your layout.

<ImageView
android:id="@+id/im_blink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/android"/>

Now simply add the following code to your Activity class file

ImageView im_blink = (ImageView) findViewById(R.id.im_blink);
final Animation animation = new AlphaAnimation((float) 0.5, 0);
animation.setDuration(500);
animation.setInterpolator(new LinearInterpolator());
animation.setRepeatCount(Animation.INFINITE);
animation.setRepeatMode(Animation.REVERSE);
im_blink.startAnimation(animation);

Note: You need to have a png image in your drawable folder which is referring in the above layout

 

blink
blink

About the author

Hi guys, i am the author of codesfor. I am a B.Tech graduate currently working as an App developer. Apart from job i am a blogger and a freelancer.

Add a Comment

Your email address will not be published. Required fields are marked *