ジャイロスコープを使用してパディングの値を制御するアプリがあります。ただし、デバイスの画面に触れたり動かしたりしない限り、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 を追加すると、機能します。しかし、画面をブロックするので、解決策ではないと思います。他の解決策はありますか?