Animation to Image

It is interesting to give animation to an image. We can animate an image in a few steps.

Recently, I used animation to an image, and after some time I wish to disable the image. For disabling the image I used setVisibility(View.GONE), but the image did not disappear even after some time. I was confused why the image did not disappear. Spending a lot of time with that, I found the mistake. If we wish to make any changes in an animated image, we should first remove the animation. Only after that we can disable the image. OK, let’s see how to do that.

ImageView in XML layout


Code you have to include in the Activity

ImageView img_animation = (ImageView) findViewById(;
	    TranslateAnimation animation = new TranslateAnimation(-500.0f, 100.0f, 0.0f, 0.0f); //new TranslateAnimation(xFrom,xTo, yFrom,yTo)
	    animation.setDuration(6000);  // animation duration 
	    animation.setRepeatCount(5);  // animation repeat count
	    animation.setRepeatMode(4);   // repeat animation (left to right, right to left )

Now, we get the animated image. If you wish to disable the image, you have to clear the animation.


Hope this blog post was helpful. Do let me know your feedback.

Leave a Reply

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