2011-10-27 49 views
1

例如,如果我将seekbar移动到100,我希望imageView在一秒内旋转到100deg。问题是如果我马上将它移动到50,它会跳到100,然后慢慢移动到50. 有没有办法将它从当前位置旋转...或者更适合这些随机度的更平滑动画的优雅解决方案?Smooth rotation

seekBar1 = (SeekBar) findViewById(R.id.seekBar1); 
arrow2 = (ImageView) findViewById(R.id.imageView1);  

seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() 
{ 
    public void onProgressChanged(SeekBar seekBar1, int progress, boolean fromUser) 
    { 
     currentSpeed.setText(""+progress); 

     RotateAnimation rotateAnimation = new RotateAnimation(fromPosition ,progress, 
       Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 
       0.5f); 
       rotateAnimation.setInterpolator(new LinearInterpolator()); 
       rotateAnimation.setDuration(1000); 
       rotateAnimation.setFillAfter(true); 
       arrow2.startAnimation(rotateAnimation); 
     fromPosition=progress;     
    } 
     public void onStartTrackingTouch(SeekBar seekSize1) {} 
     public void onStopTrackingTouch(SeekBar seekSize1) {} 
}); 

回答

0

我知道这个问题是很早以前发布的 - 但我一直在努力解决同一个问题,并提出了一个解决方案。你必须使用所谓的低通滤波器。这可以滤除一些噪音,以及传感器返回的“异常值”。看看this