2011-08-17 60 views
0

我试图让我的动画旋转直到用户点击视图。我将动画设置为旋转一次,我希望它继续进行某种循环,而不是使用.clearAnimation,这样动画不会在点击时停止一个循环。我提出的代码如此显然不起作用,但我可以考虑如何做到这一点!无限循环问题

while(keepSpinning){ 

    turntable = (ImageView)findViewById(R.id.deck1);  

    RotateAnimation r ; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO); 
    r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 
    r.setDuration(5000); 
    r.setRepeatCount(0); 

    turntable.startAnimation(r); 
    turntable.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View arg0, MotionEvent arg1) { 
      keepSpinning = false; 
      return true; 
     } 
    }); 
} 
+0

你不能在'onTouch()'中取消动画吗? 'turntable.getAnimation()。cancel()' –

+0

你可以使用runOnUi线程。 –

回答