Fade in/out animation

In order to get a view to slowly fade in or out of view, use an ObjectAnimator. As seen in the code below, set a duration using .setDuration(millis) where the millis parameter is the duration (in milliseconds) of the animation. In the below code, the views will fade in / out over 500 milliseconds, or 1/2 second. To start the ObjectAnimator's animation, call .start(). Once the animation is complete, onAnimationEnd(Animator animation) is called. Here is a good place to set your view's visibility to View.GONE or View.VISIBLE.

ViewPropertyAnimator

Every single View has a ViewPropertyAnimator object available through the animate() method. You can use that to animate multiple properties at once with a simple call. Every single method of a ViewPropertyAnimator specifies the target value of a specific parameter that the ViewPropertyAnimator should animate to.

Note: Calling start() on a ViewPropertyAnimator object is NOT mandatory. If you don't do that you're just letting the platform to handle the starting of the animation in the appropriate time (next animation handling pass). If you actually do that (call start()) you're making sure the animation is started immediately.

This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0