0

I'm testing out an animation on an ImageView. I want the ImageView to move down 1500 in 1 second and then up 1500 in the next 1 second (back to where is started). For some reason the imageView only ever does one translation and not the other. Why is this?

imageView.animate().translationYBy(1500).setDuration(1000);

imageView.animate().translationYBy(-1500).setDuration(1000);

Another example:

imageView.animate().translationYBy(1500).setDuration(1000);
imageView.animate().translationXBy(-1500).setDuration(1000);

This does the X and Y animations at the same time, I thought it would do the Y animation over 1 second and then do the X animation over the next second.

Can someone please explain where I am going wrong?

sazzad
  • 5,740
  • 6
  • 25
  • 42
Greg
  • 1
  • This happens because both animations try to run at the same time. I suggest using a timer to wait for the first animation to finish (Don't do this on the UI thread), or use an [animation listener](https://stackoverflow.com/a/21122591/1270000) to run the next animation after the first one finishes. – sorifiend Dec 22 '20 at 00:15
  • Thanks for the reply sazzad. How come a counter.setTranslationY(-1500); runs before a counter.animate().translationYBy(1500).setDuration(1000); Why are they not trying to also run at the same time? – Greg Dec 22 '20 at 03:59
  • Is it because counter.setTranslationY(-1500); is not an animation? – Greg Dec 22 '20 at 04:24

0 Answers0