Fade In and Fade Out in Android

In this blog post, I would like to explain how to give Fade In and Fade Out effects to an image in Android.

In a few steps, we can give Fade In and Fade Out effects to an image in Android.

Create ImageView in Xml Layout.

Now, Include the following code:

AlphaAnimation anim = new AlphaAnimation(1.0f, 0.0f);
anim.setDuration(1000);
anim.setRepeatCount(1);
anim.setRepeatMode(Animation.REVERSE);
imageView.startAnimation(anim);

AlphaAnimation
An animation that controls the alpha level of an object. Useful for fading things in and out.This animation ends up changing the alpha property of a Transformation.

SetDuration
Amount of time (in milliseconds) for the animation to run.

setRepeatCount
Defines how many times the animation should repeat.

setRepeatMode
Defines the animation behavior when it reaches the end and the repeat count is greater than 0 or infinite.

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 *