ImageView连续旋转

时间:2012-08-08 06:08:23

标签: android

我在罗盘应用程序中使用了ImageView,当传感器值发生变化时,它会旋转。问题是当设备达到173到186度角时,我的ImageView开始从0-360度角度连续旋转。在此应用程序运行完全正常之前,我添加了一段代码以降低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));
.
.
.
}
};

如果有人可以帮助我,那将很高兴

1 个答案:

答案 0 :(得分:0)

我的猜测是你正在从笛卡尔坐标转换到极坐标,这种方式在一个轴接近零时是不稳定的。但也许它是RotateRunnable中的东西。

相关问题