在TouchEvent上使用TranslateAnimation()

时间:2011-12-13 17:18:22

标签: android translate-animation

我一直在开发游戏,我很困惑我如何在TranslateAnimation上使用TouchEvent? ,请看我的代码,有些不对劲!? Fstball尚未翻译,有任何想法吗?

@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
int X = (int) event.getX();
int Y = (int) event.getY();
int action = event.getAction();
if (action == MotionEvent.ACTION_UP){
TranslateAnimation anim = new TranslateAnimation(FstBall.getLeft(),X,FstBall.getTop()
,Y);
anim.setFillAfter(true);
anim.setDuration(1000);
FstBall.setAnimation(anim);
} else {
Toast.makeText(this,"Touch any points to move.", Toast.LENGTH_SHORT).show();
}
return true;
}

1 个答案:

答案 0 :(得分:2)

你应该像这样开始你的动画:

FstBall. startAnimation(anim); // FstBall is a View