Android Views Animation Tutorial




In this section i will try to explain the 4 types of animation on views which can overall change the impression of the views.

The attached program demonstrates the available types of animations which are:
Alpha - Causes a fading in or fading out effect.
Scale - The view's size smoothly changes.
Rotate - The view rotates.
Translate - The view moves to a different position.


You can individually use these animations or you can also combine these animations into one. Combining of animations is done with help of animation set.First i will explain how to use these animations individually.

ALPHA ANIMATION: Alpha animation is used in fading in and fading out of views. 

<alpha 
android:fromAlpha="0.0" 
android:toAlpha="0.9"
android:duration="3000" />

SCALE ANIMATION: Scale animation is used for changing the size of view.


<scale 
android:fromXScale="1.0" 
android:fromYScale="1.0"
android:toXScale="2.0" 
android:toYScale="2.0" 
android:duration="3000" />

ROTATE ANIMATION: Rotate animation is used for rotating a view around a particular axis.


<rotate 
android:fromDegrees="359" 
android:toDegrees="0"
android:duration="3000" 
android:pivotX="50%" 
android:pivotY="50%" />

TRANSLATE ANIMATION: Translate animation is used to change the position of a particular view.

<translate 
android:fromXDelta="300%" 
android:toXDelta="0%" 
android:fromYDelta="0%"
android:toYDelta="0%" 
android:duration="3000" 
android:zAdjustment="bottom" />

You need to keep these XML files in anim folder in res folder.
And finally to use this application in your Activity you need to use the following piece of code:




final Animation anim=AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation);// where animation is the name of the anim file which contains any of the above mentioned animation.




Download free source code here.

Comments

Popular Posts