JR Tan
JR Tan

Reputation: 1725

android UI react weird in gyroscope event

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?

Upvotes: 1

Views: 176

Answers (1)

dors
dors

Reputation: 5892

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

Upvotes: 1

Related Questions