2016-05-18 10 views
0

後、私は、コードは最初の時間のために働くのアニメーションを繰り返し、他の

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.lay); 
     rel = (LinearLayout) findViewById(R.id.rel); 
     rel.setBackgroundDrawable(getResources().getDrawable(R.drawable.gradient_background)); 


     animation = new AlphaAnimation(1, 0); 
     animation.setDuration(500); 
     animation.setInterpolator(new LinearInterpolator()); 
     animation.setRepeatCount(3); 
     rel.startAnimation(animation); 

     animation1 = new AlphaAnimation(1, 0); 
     animation1.setDuration(1500); 
     animation1.setInterpolator(new LinearInterpolator()); 
     animation1.setRepeatCount(3); 

     animationchala(); 




    } 

    public void animationchala(){ 
     animation.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 

      } 

      public void onAnimationEnd(Animation animation) { 
       animation.setAnimationListener(null); 

       rel.startAnimation(animation1); 


      } 

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

     animation1.setAnimationListener(new Animation.AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation1) { 

      } 

      public void onAnimationEnd(Animation animation1) { 
       animation1.setAnimationListener(null); 
       rel.startAnimation(animation); 


      } 

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

ためのAndoridに次のコードをしようとしています。無限

アニメーションがanimation1が開始されて終了した場合、その後、animation1終了し、アニメーションが再び開始されますが、animation1を再び開始しなければならない場合、今それが停止し、どのように私はアニメーションを繰り返すことができ、次々

+0

無限ループを使用しようとしましたか? while(true)? – michoprogrammer

答えて

1

問題がです新規のアニメーションを開始したときにanimationListenersnullに設定している場合があります。これにより、アニメーションを開始した後で停止します。このようにコードを並べ替えるだけです。

public void animationchala(){ 
    animation.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation) { 

     } 

     public void onAnimationEnd(Animation animation) { 

      rel.startAnimation(animation1); 


     } 

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

    animation1.setAnimationListener(new Animation.AnimationListener() { 
     @Override 
     public void onAnimationStart(Animation animation1) { 

     } 

     public void onAnimationEnd(Animation animation1) { 
      rel.startAnimation(animation); 


     } 

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