3
我想要做的是將多個視圖設置爲PIXELS中的特定位置! 我正在使用TranslateAnimation。我想從顯示器的左上角進行動畫處理,我相信x:0和y:0到可變位置。Android TranslateAnimation以像素爲特定位置
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);
}
我的問題是,死動畫只是沒有做它應該做的(像素動畫以動畫方式不符合我的輸入),爲什麼呢?我究竟做錯了什麼?
我的Logcat輸出,你可以看到它在animateObject方法是完全正確的,像素匹配我的願望。
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 ...
請問您可以粘貼一些解決方案的代碼 – Kishore