我有一些代码可以创建一个名为路径的点列表。
这是一个示例列表:[[1, 3], [2, 3], [2, 4]]
这是我编写的代码,用于按顺序对这些点进行动画处理:
ArrayList<Animator> movements = new ArrayList<>();
int prevY = start[1];
int prevX = start[0];
for (int[] square : path) {
ObjectAnimator motion = new ObjectAnimator();
float[] coord = screenFromGrid(square[0], square[1], gridSizeY);
long speed = (long) (6000.0 / this.displayMetrics.widthPixels);
speed = (long) (speed * getSquareSize(gridSizeY));
if (square[0] != prevX) {
motion = ObjectAnimator.ofFloat(this.sprite1, "x", coord[0]);
motion.setInterpolator(new LinearInterpolator());
motion.setDuration(speed);
movements.add(motion);
prevX = square[0];
} else if (square[1] != prevY) {
motion = ObjectAnimator.ofFloat(this.sprite1, "y", coord[1]);
motion.setInterpolator(new LinearInterpolator());
motion.setDuration(speed);
movements.add(motion);
prevY = square[1];
}
}
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playSequentially(movements);
animatorSet.start();
问题是动画在中间完全停止而没有抛出任何错误。
我检查了调试器,它说所有动画都已正确存储。
有谁知道为什么会这样?