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,
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) {
// 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!
Mehul joisar
source share