我想要做的是在 PIXELS 中将多个视图设置为特定位置的动画!我为此使用了 TranslateAnimation。我想从显示器的左上角动画,我相信 x: 0 和 y:0 到一个可变位置。
private void drawGameField() {
TextView [] tvs = new TextView[10];
for(int i = 0; i < tvs.length; i++) {
tvs[i] = new TextView(this);
tvs[i].setX(i * 50);
tvs[i].setY(i * 50);
tvs[i].setText(i + "");
gamelayout.addView(tvs[i]); // relativelayout that is created in the onCreate method
animateObject(1000, tvs[i], 0, (int) tvs[i].getX(), 0, (int) tvs[i].getY());
}
}
private void animateObject(int time, TextView tv, int fromDeltaX, int toDeltaX, int fromDeltaY, int toDeltaY) {
Log.i("Animation", "Animating to: x: " + toDeltaX + ", y: " + toDeltaY);
TranslateAnimation t = new TranslateAnimation(fromDeltaX, toDeltaX,
fromDeltaY, toDeltaY);
t.setDuration(time);
tv.startAnimation(t);
}
我的问题是,动画只是没有做它应该做的事情(动画动画的像素与我的输入不匹配),为什么?我究竟做错了什么?
如您在 animateObject 方法中所见,我的 Logcat 输出完全正确,像素符合我的要求。
LogCat 输出如下:
Animation Animating to: x: 0, y: 0
Animation Animating to: x: 50, y: 50
Animation Animating to: x: 100, y: 100
Animation Animating to: x: 150, y: 150
Animation Animating to: x: 200, y: 200 ...