Android ImageView Blink Animation

In this Android Example, we will see how to make an ImageView blink using AnimationDrawable class.

Steps to create frame-by-frame animations using AnimationDrawable

  1. define animation in an XML file, place it in res/drawable/ folder and set it as background to a View object.
  2. call start() to run the animation

Create an Android Project

Create a new Android project and name it as ImageViewBlink.

Download “ImageView Blink Animation” ImageViewBlink.zip – Downloaded 1695 times – 1 MB

Resources

colors.xml

Create a new file res/values/colors.xml and copy paste the following content.

strings.xml

Open res/values/strings.xml and edit to have the content as shown below.

Layout file – activity_main.xml

This is the main layout file which holds the ImageView.
Open res/layout/activity_main.xml and edit to have the content as shown below.

Drawable – new_arrivals_animation.xml

Create a new file res/drawable/new_arrivals_animation.xml and copy paste the following content.
An AnimationDrawable defined in XML consists of a single <animation-list> element, and a series of nested <item> tags. Each item defines a frame of the animation.

Source files

MainActivity class

This is the main activity class which displays the ImageView.

Output