Question

I have an app that used gyroscope to control the value of the padding. However it doesn't update the UI unless I'm touching or moving the device screen.

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]));
}

However when I added a temporary textView that update value according to gyro event, it works. But I don't think it's a solution as it will block the screen. Is there an other solution?

Was it helpful?

Solution

Does calling imgv.invalidate() after setting the padding work?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top