Reputation: 1136
I'm trying to move an ImageView with this code:
img.animate().translationY(110).setDuration(1500);
But if I try to move it again later with something like:
img.animate().translationY(-110).setDuration(1500);
The ImageView moves from where it used to be before I moved it in the first place. What I would expect is for it to return to it's original position. What am I missing here?
Upvotes: 0
Views: 3743
Reputation: 11
TranslateAnimation animationDown = new TranslateAnimation(00.0f, 00.0f, 00.0f, 500);
animationDown.setDuration(800);
animationDown.setRepeatMode(android.view.animation.Animation.REVERSE);
animationDown.setRepeatCount(android.view.animation.Animation.INFINITE);
This will make the image move straight down then reverse its track back up to its original spot maintaining speed. Also take note you can make multiple of these and add them to one animation set to get the desired square pattern i believe how you would store it into a set is as such...
AnimationSet example = new AnimationSet(true);
example.addAnimation(animationDown);
"" and so on until
s.setStartTime();
or
s.startAnimationSet();
Upvotes: 0
Reputation: 642
you have to move it after (in your case) 1.5 seconds is passed
float originalPosition = img.getY();
img.animate().translationY(110).setDuration(1500).start();
img.animate().translationY(originalPosition).setStartDelay(1500).setDuration(1500).start();
im not so sure about the method names..
Upvotes: 0
Reputation: 106
Maybe you could just get the translation and add it?
public void ClickMoveDown{
float distance = 100;
Move (0,distance)
}
private void Move (float x, float y){
img.animate().translationX(img.getTranslationX+x).setDuration(1500);
img.animate().translationY(img.getTranslationY+y).setDuration(1500);
}
Upvotes: 0
Reputation: 560
you should use animationSet and also -
animationSet.setFillAfter(true);
Good luck.
Upvotes: 0