2012-08-08 70 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中的一些东西。