The animation only moves pixels on the screen, not the position of the object. To set where you left off, set
animation.setFillAfter(true);
To actually move the position of an object, examine the use of a modified version of the code snippet below.
MarginLayoutParams marginParams = new MarginLayoutParams(object.getLayoutParams()); marginParams.setMargins(left, (top+hol2), left, 0); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(marginParams); object.setLayoutParams(layoutParams);
Regarding the fact that onAnimationEnd is called multiple times, I will need to see some code.
The only thing I know to manually stop the animation would be
animation.cancel(); (may not work for 2.1, can't remember)
or
object.clearAnimation();
Sample code below:
upmotionleft = new TranslateAnimation(0, 0, 0, 600); upmotionleft.setDuration(2000); upmotionleft.setFillEnabled(true); upmotionleft.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationEnd(Animation animation) {
This code was copied and pasted from my project, but it has changed a bit, it should still work.
source share