2013-07-01 22 views
1

我有一个应用程序,使用陀螺仪来控制填充的值。但是,除非我触摸或移动设备屏幕,否则它不会更新UI。Android UI在陀螺仪事件中反应怪异

private void GyroFunction(SensorEvent event) { 
    SensorManager 
      .getRotationMatrixFromVector(mRotationMatrix, event.values); 
    SensorManager.remapCoordinateSystem(mRotationMatrix, 
      SensorManager.AXIS_X, SensorManager.AXIS_Z, mRotationMatrix); 
    SensorManager.getOrientation(mRotationMatrix, orientationVals); 

    // I must put this line of code to make the UI thread update every time 
    tempTxtView.setText(String.valueOf(orientationVals[2])); 

    imgv.setPadding((int) Math.round(orientationVals[0]), 
      (int) Math.round(orientationVals[1]), 
      (int) Math.round(orientationVals[0]), 
      (int) Math.round(orientationVals[1])); 
} 

然而,当我增加了一个临时的TextView根据陀螺事件更新值,它的工作原理。但我不认为这是一个解决方案,因为它会阻止屏幕。还有其他解决方案吗?

回答

1

设置填充工作后调用imgv.invalidate()吗?

+0

谢谢!它现在工作真棒。你知道我们为什么需要使它无效吗? –

+0

不...:/但我想这是需要提神的东西之一 – dors