1

How can I change the position of these ImageViews by giving them the position of another? (Swapping them around in Slow Motion)

blue = (ImageView) findViewById(R.id.imageB);
red = (ImageView) findViewById(R.id.imageR);
Green = (ImageView) findViewById(R.id.imageG);
int x = blue.getLeft();
int y = blue.getTop();

int x1 = red.getLeft();
int y1 = red.getTop();

int x2 = Green.getLeft();
int y2 = Green.getTop();


Green.setLeft(x);
Green.setTop(y);

blue.setLeft(x1);
blue.setTop(y1);

red.setLeft(x2);
red.setTop(y2);`
Maher Ismaail
  • 1,663
  • 2
  • 15
  • 26
  • Why you don't keep the ImageViews at their position and switch their background? – Rami Apr 11 '15 at 13:41
  • I want to give them some animation ... by moving them slowly – Maher Ismaail Apr 12 '15 at 12:56
  • Attempted to make this more understandable, it's certainly a riddle. I do recommend mentioning what the actual problem your having is, for example posting relevant crash logs or expected vs reality in terms of outcomes. – Broak Apr 12 '15 at 22:22

1 Answers1

1

In android there is a difference between layout and animations. To animate images use TranslateAnimation, as explained here.

How ever in the end of the animation, your images will return to their original position as the layout did not changed. So you need to set a callback to when animation is finished and change your images background so the layout will mach the animation.

Also there are several ways to achieve this, read more about animations here.

Community
  • 1
  • 1
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216