消除AnimationSet中动画之间过渡的暂停

时间:2016-04-21 17:27:29

标签: android animation

我有一个AnimationSet,它以矩形方式在视图中移动:

private void animate(final View viewToAnimate) {
    final AnimationSet animationSet = new AnimationSet(true);

    TranslateAnimation animationOne = new TranslateAnimation(0, ((int) HelperPixel.convertDpToPixel(this.getApplicationContext(), 70)), 0, 0);
    animationOne.setDuration(500);

    TranslateAnimation animationTwo = new TranslateAnimation(0, 0, 0, ((int) HelperPixel.convertDpToPixel(this.getApplicationContext(), 140)));
    animationTwo.setDuration(1000);
    animationTwo.setStartOffset(500);

    TranslateAnimation animationThree = new TranslateAnimation(0, ((int) HelperPixel.convertDpToPixel(this.getApplicationContext(), -140)), 0, 0);
    animationThree.setDuration(1000);
    animationThree.setStartOffset(1500);

    TranslateAnimation animationFour = new TranslateAnimation(0, 0, 0, ((int) HelperPixel.convertDpToPixel(this.getApplicationContext(), -140)));
    animationFour.setDuration(1000);
    animationFour.setStartOffset(2500);

    TranslateAnimation animationFive = new TranslateAnimation(0, ((int) HelperPixel.convertDpToPixel(this.getApplicationContext(), 70)), 0, 0);
    animationFive.setDuration(500);
    animationFive.setStartOffset(3500);

    animationSet.addAnimation(animationOne);
    animationSet.addAnimation(animationTwo);
    animationSet.addAnimation(animationThree);
    animationSet.addAnimation(animationFour);
    animationSet.addAnimation(animationFive);
    animationSet.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {}

        @Override
        public void onAnimationEnd(Animation animation) {
            viewToAnimate.startAnimation(animationSet);
        }

        @Override
        public void onAnimationRepeat(Animation animation) {}
    });

    viewToAnimate.startAnimation(animationSet);
}

我现在的问题是这些动画之间有一个很小但非常明显的停顿。我不希望这样。我想在动画之间平滑过渡,以便用户认为它是一个动画。他不应该看到有几个动画。

我怎样才能做到这一点?

0 个答案:

没有答案