There are three types of animations available for Android Programmers- Translate Animation, Alpha Animation and Object Animation. Translate Animation and Alpha Animation can change the visual appearance of an object, but they cannot change the objects themselves. That is, if you apply a translate animation to a view, it would move to a new position but its click events would not get fired whereas the click events would still get fired at its previous position. This happens because the view is still at its original position. In order to overcome this, Honeycomb came up with a new animation method "Object Animation". which actually moves an object.
Translate Animation
Translate Animation controls the position and location of a layout or button or any view on which animation is being applied. It can move an object either in x direction or y direction.
For creating a Translate animation you need to create an object of TranslateAnimation.
TranslateAnimation transAnimation= new TranslateAnimation(fromXposition, toXPosition, fromYPosition, toYPosition); //fromXposition- x coordinate from where animation should start //toXPosition- x coordinate at which animation would end //fromYPosition- y coordinate from where animation should start. //toYPosition- y coordinate at which animation would end. //You can also set duration for the animation that means you can set for how long the animation should last: transAnimation.setDuration(1000); //You can now apply the animation to a view view.startAnimation(transAnimation);
Alpha Animation
Alpha Animation is another type of Animation available for Android Programmers which controls the alpha level of any view. Alpha Animation is used to fade in and fade out a view.
For creating an AlphaAnimation you need to create an object of AlphaAnimation.
AlphaAnimation alphaAmin = new AlphaAnimation(fromAlphaLevel, toAlphalevel); //fromAlphaLevel- alpha value to start from //toAlphalevel- alpha value to reach. //alpha value = 1.0 means fully opaque and alpha value = 0.0 means fully transparent.
Object Animation
As we said above, Object Animation is the only animation which actually moves an object. "Object Animation" introduced during Honeycomb development.
You can create Translate animation as well as Alpha animation using ObjectAnimator.
ObjectAnimator transAnimation= ObjectAnimator.ofFloat(view, propertyName, fromX, toX); transAnimation.setDuration(3000); transAnimation.start(); //"view"- this is the view(say, a button) on which animation is to be applied.
You have missed rotate animation and scale animation. Also the object animation example is incomplete