题
我创建了一系列坐标。图像的中心应通过这些坐标移动。我已经使用了翻译来实现它。但是在动画期间,图像在最后两个坐标中移动。以下是我的代码:
private void CreateAnimationAndRun() {
// move to the different coordinates one by one
for(int k=0; k<xpoints.length; k++) {
if(k==0) {
x1 = xstart;
y1 = ystart;
} else {
x1 = xpoints[k-1];
y1 = ypoints[k-1];
}
x2 = xpoints[k];
y2 = ypoints[k];
TranslateAnimation translateAnimation = new TranslateAnimation(x1, x2, y1, y2);
translateAnimation.setDuration(1000);
translateAnimation.setAnimationListener(anim_listener);
imv1.startAnimation(translateAnimation);
}
}
单击按钮已调用上述功能。
解决方案
我自己只有几个小时来播放Android动画,所以我希望这不会误导。
我认为问题在于,您的循环正在用每次迭代覆盖动画,因此,当您运行时,您会看到所有的是最后一个动画(在最后两个点之间)。
相反,需要在不同的开始时间生成动画。据我了解,到目前为止,最好的方法是创建一个动画网,并使用循环将其加载到通过SetstartOffSet()启动时间不同的动画加载。然后,在单击时,您只需启动Animationset即可。或者,单击可以在循环中创建它们,并使用setstarttime()使它们在适当的点上播放。
不隶属于 StackOverflow