2011-10-27 64 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