1

我有一个使用陀螺仪来控制填充值的应用程序。但是,除非我触摸或移动设备屏幕,否则它不会更新 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 时,它可以工作。但我不认为这是一个解决方案,因为它会挡住屏幕。还有其他解决方案吗?

4

1 回答 1

1

设置填充后调用 imgv.invalidate() 是否有效?

于 2013-07-01T04:43:30.587 回答