I want to move an image from 0,0 to 100,100 on android. I’m using translate animation to do so:
public void moveImage() {
// move image from 0,0 to 100,100
mAnimationTranslate = new TranslateAnimation(0, 100, 0, 100);
mAnimationTranslate.setDuration(1000);
mAnimationTranslate.setAnimationListener(this);
this.startAnimation(mAnimationTranslate);
}
public void onDraw (Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(bmp, x, y, null);
}
public void onAnimationEnd(Animation animation) {
// stop animation and draw the image at 100,100
x = 100;
y = 100;
}
The problem is when the animation finishes at 100,100, the image will move to 200,200 for a short time and back to 100,100 in the end. Is there any problem in my code? How to let the image stop at 100,100 correctly?
I think you need to use
There is no need for the
onAnimationEndevent.Not sure why it’s moving to
200, 200though.