Android为什么这个动画不循环

时间:2017-02-08 16:29:38

标签: android loops animation

 animation = new TranslateAnimation(lrobjkt.getX(),400,0,0);
animationback = new TranslateAnimation(400,lrobjkt.getX(),0,0);
 // set Animation for 5 sec
 animation.setDuration(6000);
 animationback.setDuration(7000);
 //for button stops in the new position.
 animation.setFillAfter(true);
 animationback.setFillAfter(true);
 lrobjkt.startAnimation(animation);

 animation.setAnimationListener(new AnimationListener(){

   @Override
   public void onAnimationStart(Animation animation){}

   @Override
   public void onAnimationRepeat(Animation animation){}

   @Override
   public void onAnimationEnd(Animation animation){

        animationback = new TranslateAnimation(400,lrobjkt.getX(),0,0);
       animationback.setDuration(7000);
       animationback.setFillAfter(true);
       lrobjkt.startAnimation(animationback);
   }
});

 animationback.setAnimationListener(new AnimationListener(){

   @Override
   public void onAnimationStart(Animation animation){}

   @Override
   public void onAnimationRepeat(Animation animation){}

   @Override
   public void onAnimationEnd(Animation animation){
     animation = new TranslateAnimation(lrobjkt.getX(),400,0,0);
     animation.setDuration(6000);
    animation.setFillAfter(true);
       lrobjkt.startAnimation(animation);
   }
});

一个动画运行一次,另一个动画运行两次,但它应该循环运行。我的另一个问题是我如何移动让我们说文本视图从哪里到设备的最大xDelta位置?

1 个答案:

答案 0 :(得分:0)

初始化时,只需在repeatCount上设置TranslateAnimation即可。

animation.setDuration(6000);
animation.setRepeatCount(100) // will repeat 100 times
animationback.setDuration(7000);
animationback.setRepeatCount(100); //will repeat 100 times
  //for button stops in the new position.
animation.setFillAfter(true);
animationback.setFillAfter(true);