Animate the image icon from the touch screen to the upper right corner?

I am working on an Android application onlineShopping. I need to apply some animation.

  • The image of the basket is displayed in the upper right corner of the screen.
  • List of items on the screen of each item with the "Add to Cart" button.
  • When the user clicks this button, I have to play the animation.
  • I have one fixed image, which should be animated from touch to cart-image, located in the upper right corner of the screen.

Please help me.

Thanks in advance.

Update:

I tried this to move an image from one place to another.

TranslateAnimation anim = new TranslateAnimation(0,0,200,200); anim.setDuration(3000); img.startAnimation(anim); 

This image I want to animate from touch to the upper right corner. enter image description here

+3
android animation viewanimator
source share
3 answers

Ultimately, you want to move the view from one position to another with animation.

Step 1: get the starting position of this view

 int fromLoc[] = new int[2]; v.getLocationOnScreen(fromLoc); float startX = fromLoc[0]; float startY = fromLoc[1]; 

Step 2: get the destination

 int toLoc[] = new int[2]; desti.getLocationOnScreen(toLoc); float destX = toLoc[0]; float destY = toLoc[1]; 

Step 3: create a class to control the animation

  public class Animations { public Animation fromAtoB(float fromX, float fromY, float toX, float toY, AnimationListener l, int speed){ Animation fromAtoB = new TranslateAnimation( Animation.ABSOLUTE, //from xType fromX, Animation.ABSOLUTE, //to xType toX, Animation.ABSOLUTE, //from yType fromY, Animation.ABSOLUTE, //to yType toY ); fromAtoB.setDuration(speed); fromAtoB.setInterpolator(new AnticipateOvershootInterpolator(1.0f)); if(l != null) fromAtoB.setAnimationListener(l); return fromAtoB; } } 

Step 4: add an animated animator and start the animation in the desired view

  AnimationListener animL = new AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { //this is just a method call you can create to delete the animated view or hide it until you need it again. clearAnimation(); } }; 

// now start the animation as follows:

 Animations anim = new Animations(); Animation a = anim.fromAtoB(startX, startY, destX, destY, animL,850); v.setAnimation(a); a.startNow(); 

Hope this will be helpful!

+5
source share

I think you are exactly looking, you can check the link

here

enter image description here

+1
source share

check this example, hope this helps u: http://developer.android.com/training/animation/zoom.html

0
source share

All Articles