【发布时间】:2023-03-20 06:09:01
【问题描述】:
我想在 android 上将图像从 0,0 移动到 100,100。我正在使用翻译动画来做到这一点:
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;
}
问题是当动画在 100,100 处结束时,图像会在短时间内移动到 200,200 并最终回到 100,100。我的代码有问题吗?如何让图片正确停在100100?
【问题讨论】: