0

I have three animations like scale, translate and scale. I play those animations in order. First two is working fine but last scale animation reset the position of view to original. If I remove last scale animation, it's working fine the view stay the new position after translate animation. Do you have any idea about this behavior?

AnimationSet animationSet = new AnimationSet(false);
animationSet.setFillAfter(true);

ScaleAnimation scaleAnimation1 = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f);
scaleAnimation1.setDuration(500);
scaleAnimation1.setFillAfter(true);

TranslateAnimation moveAnim = new TranslateAnimation(0, -x, 0, -y);
moveAnim.setDuration(1000);
moveAnim.setStartOffset(500);
moveAnim.setFillAfter(true);

ScaleAnimation scaleAnimation2 = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f);
scaleAnimation2.setDuration(500);
scaleAnimation2.setStartOffset(1000);
scaleAnimation2.setFillAfter(true);
scaleAnimation2.setFillBefore(true);

animationSet.addAnimation(scaleAnimation1);
animationSet.addAnimation(moveAnim);
animationSet.addAnimation(scaleAnimation2);
onur taskin
  • 929
  • 1
  • 14
  • 33
  • "reset the position of view to original"- can you be more precise? Does the reset look like a jump across the screen? And where does it reset to. There is a common misunderstanding / design infelicity with Android SDK's animations that can lead to this. – Tom Oct 04 '13 at 09:07
  • I mean, before animation the view is center of screen. After translate animation the view goes to top. When 'scaleAnimation2' start, the view also goes back to center of screen – onur taskin Oct 04 '13 at 10:36

1 Answers1

2

scaleAnimation2.setFillAfter(true); - If fillAfter is true, the transformation that this animation performed will persist when it is finished

scaleAnimation2.setFillBefore(true);- If fillBefore is true, this animation will apply its transformation before the start time of the animation.

These two properties cannot work simultaneously, and the one which set later is effective. So, remove scaleAnimation2.setFillBefore(true); may solve your problem.

Zhenghong Wang
  • 2,117
  • 17
  • 19