缩放动画重置位置



我有三个动画,如缩放,平移和缩放。我按顺序播放这些动画。前两个工作正常,但最后一个比例动画将视图的位置重置为原始位置。如果我删除最后一个比例动画,它可以正常工作,平移动画后视图保持新位置。你对这种行为有任何想法吗?

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);

scaleAnimation2.setFillAfter(true); - 如果 fillAfter 为 true,则此动画执行的转换将在完成后保留

scaleAnimation2.setFillBefore(true); - 如果 fillBefore 为 true,则此动画将在动画开始时间之前应用其转换。

这两个属性不能同时工作,稍后设置的属性是有效的。因此,删除scaleAnimation2.setFillBefore(true);可能会解决您的问题。

最新更新