2012-08-08 96 views
-1

我在我的羅盤應用程序中使用了一個ImageView,它在傳感器值發生變化時旋轉。問題是當設備達到173至186度角度時,我的ImageView開始從0-360度角連續旋轉。在這個應用程序運行完美之前,我添加了一段代碼以降低ImageView的旋轉速度後開始了這個特殊問題。ImageView不斷旋轉

的方法加入到降低轉速

protected float[] lowPass(float[] input, float[] output) { 
    if (output == null) return input; 

    for (int i=0; i<input.length; i++) { 
     output[i] = output[i] + ALPHA * (input[i] - output[i]); 
    } 
    return output; 
} 

傳感器事件監聽器從那裏方法被調用

private SensorEventListener mySensorEventListener = new SensorEventListener() { 
. 
. 
. 
public void onSensorChanged(SensorEvent event) { 
. 
. 
. 
SensorManager.getOrientation(rotationMatrix, orientationValues); 

    accelVals = lowPass(orientationValues, accelVals); 

    azimuth = (int) Math.toDegrees(accelVals[0]); 
    azimuth = (azimuth +360)%360; 
    allowRotating=true; 
    dialer.post(new RotateRunnable(azimuth)); 
. 
. 
. 
} 
}; 

會很高興如果任何人能幫助我

+0

請嘗試將其降至更具體的問題。 – poolie 2012-08-08 06:11:15

+0

編輯問題請檢查。 – 2012-08-08 06:50:01

回答

0

我的猜測是你在做一個從笛卡兒到極座標的轉換,當一個軸接近於零時,這種方式是不穩定的。但也許這是RotateRunnable中的一些東西。