android上使用平移动画移动图像时出现的问题

android上使用平移动画移动图像时出现的问题,android,animation,Android,Animation,我想在android上将图像从0,0移动到100100。我正在使用“平移动画”来执行此操作: public void moveImage() { // move image from 0,0 to 100,100 mAnimationTranslate = new TranslateAnimation(0, 100, 0, 100); mAnimationTranslate.setDuration(1000); mAnimationTranslate.setAni

我想在android上将图像从0,0移动到100100。我正在使用“平移动画”来执行此操作:

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;
}

问题是,当动画在100100处结束时,图像将在短时间内移动到200200,最后返回到100100。我的代码有问题吗?如何让图像正确地停止在100100?

我认为您需要使用

animation.setFillAfter(true); //to retain the properties after the animation finishes.
无需执行onAnimationEnd事件。
不知道为什么它会移动到
200,200

我也有同样的问题,我知道调用
animation.setFillAfter(true)
不是正确的方法,因为它只在动画的最后一个位置绘制视图的图片,但真实视图的位置与以前一样。也许图像没有问题,但如果你想用按钮或类似的东西来尝试,你会意识到这一点