Frame-by-frame animation in Android

Sometimes we need to add some special animation to indicate changes in the view state and emphasise this changes via visual representation. For example I decided to made custom animation of the “like quote” feature in my application. Initially quotation has two different states – favourite and normal. These states represented by ImageView:

star_anim_frame0

star_anim_frame8

 

 

 

So, my task was to draw some transition between these states.

First of all, I’ve created a few images (frames) with transitional states of the star. After that we can put the frames into ./drawables/star_on_animation.xml  and ./drawables/star_of_animation.xml.

First file contents

The second is almost the same except of reversed frames order. Take a note that we used parameter android:oneshot="true". Its used to launch animation only once.

Now we can use this animation drawables in our code:

I check “animation direction” and launch proper animation for that. The result will looks like that:

One thought on “Frame-by-frame animation in Android”

Leave a Reply