如何用随机方向动画android Imageview?

时间:2014-03-05 09:57:56

标签: android animation imageview

我想开发类似下图的应用程序

enter image description here

我想将图像视图2,3,4,5,6设置为imageview 1,反之亦然

请任何人帮我解决这个问题

1 个答案:

答案 0 :(得分:2)

int distance = 100; //the distance to move in pixels
int duration = 500; //the duration of the animation in ms

double direction = Math.random() * 2 * Math.PI;

int translationX = Math.cos(direction) * distance;
int translationY = Math.sin(direction) * distance;

yourImageView.animate().translationX(translationX).translationY(translationY).setDuration(duration).start();