문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top