Programming/Non programming

Tuesday, March 30, 2010

Android:Basic Animation samples

Android:

Basic Animation handling..:

To create basic animations like fade-in, fade-out, scale animation(like zooming..) etc. follow the steps as described below:

1. Create your project as usual.

2. Create a folder called "anim" under "res" folder. It will look like "res/anim"

3. Under "anim" folder, create a empty XML file for animation in the name as you wish. I named that as "fade.xml"

Add and test the following code into that XML file.

*** For "FADE-IN" animation: //in fade.xml




Call it in your code as below for sample:

public void HandleAnimation(View v)
{
v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade)); //xml name fade.xml
}

==============================================================================================

*** For image "SCALING" animation: //in fade.xml




Call it in your code as below for sample:

public void HandleAnimation(View v)
{
v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade));//xml name fade.xml
}

==============================================================================================

*** For image "SLIDE FROM LEFT and RIGHT" animation: //in fade.xml

For Push LEFT IN:



For Push LEFT OUT:




Call it in your code as below for sample:

public void HandleAnimation(View v)
{
v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade));//xml name fade.xml
}

==============================================================================================

*** For "FADE AND AWAY" animation: //in fade.xml



Call it in your code as below for sample:

public void HandleAnimation(View v)
{
v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade));//xml name fade.xml
}

==============================================================================================

*** For "SHAKE IMAGE" animation:

Add Two .xml files for this. First name it as anything as you wish, add the code below, fade.xml:




Add the second file with the below code and name it as "cycle_7.xml" ,

cycle_7.xml:




Call it like below in your code anywhere:

public void HandleAnimation(View v)
{
v.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade));//xml name fade.xml
}

You will find shake animation is happening nicely there !!!!!!!!!!!!

==============================================================================================


Cheers!

M.P.Prabakar
Senior Systems Analyst.



Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..

4 comments:

  1. Hello Prabakar...

    I'm Cristian :) I follow your blog because I've learned a lot of android tips. I'm starting in the android programming and this blog is really useful.

    Thank you (and thank Jonathan) for your excellet work :)

    ReplyDelete
  2. i want full code...u did great job plz post full code.:)

    ReplyDelete
  3. its really so useful i really learnt a lot from this blog thanks a lot :)

    ReplyDelete
  4. nice one, liked it :-)

    ReplyDelete