Android TranslateAnimation for specific pixel position
What I want to do is animate multiple views in a specific position, in PIXELS! I use TranslateAnimation for this. I want to animate in the top left corner of the display and I believe x: 0 and y: 0 in a variable position.
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);
}
My problem is that die Animation just doesn't do what it is supposed to do (the pixels that the animation animation doesn't match my input), why? What am I doing wrong?
My Logcat output, as you can see in the animateObject method, is absolutely correct, the pixels match my desires.
LogCat is output as follows:
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 ...
+3
source to share