-1

I hava a imageview. I put on specific position(specific x and y) on my constraint layout. I want to move(fly with animation) this imageview from random x y positions(for example out of screen) to specific positions that i put before on constraint layout.

I have tried translate animation. it didn't work.

{imageView4.animate().yBy(-200).y(imageView4.getY()).xBy(-200).x(imageView4.getX()).setDuration(4000);}

1 Answers1

1

Method yBy(value) allow you to move element to value relatively from current coordinate. Method y(value) allow you to move element to abslute value coordinate. So you need write this code:

imageView4.setX(startValueX);
imageView4.setY(startValueY);
imageView4.animate().x(endValueX).y(endValueY).setDuration(4000);

Notice that values given in pixels. If you need dp you have to convert px in dp.

Sergey Melnik
  • 121
  • 1
  • 5