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.
ObjectAnimator is a subclass of ValueAnimator with the added ability to set the calculated value to the property of a targetView.
Just like in the ValueAnimator, there are two ways you can create the ObjectAnimator:
(the example code animates an alpha of a View from 0.4f to 0.2f in 250ms)
From xml (put it in the /res/animator)
Shake animation of an ImageView
Under res folder, create a new folder called "anim" to store your animation resources and put this on that folder.
Create a blank activity called Landing
And the method for animate the imageview on Landing.java
This example displays a transaction for an image view with only two images.(can use more images as well one after the other for the first and second layer positions after each transaction as a loop)
add a image array to res/values/arrays.xml
ValueAnimator introduces a simple way to animate a value (of a particular type, e.g. int, float, etc.).
The usual way of using it is:
Create a ValueAnimator that will animate a value from min to max
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