0
我使用OrientationEventListener()檢測方向變化,但它給連續值。我只想要四個值爲每個方向即PORTRAIT,REVERSE_PORTRAIT,LANDSCAPE和REVERSE_LANDSCAPE MODE.What我應該做什麼來獲得值只有方向改變。我的問題是我想要檢測方向,當設備快速從景觀模式轉換爲反向景觀模式。我想調用currentScreenOrientation()函數只有一次方向更改,但現在它調用它的每個值之間的0到359.傳感器值爲每四個類型的方向
mOrientationEventListener = new OrientationEventListener(this,
SensorManager.SENSOR_DELAY_NORMAL) {
@Override
public void onOrientationChanged(int arg0) {
currentScreenOrientation();
}
};
if (mOrientationEventListener.canDetectOrientation()) {
Toast.makeText(this, "Can DetectOrientation", Toast.LENGTH_LONG)
.show();
mOrientationEventListener.enable();
} else {
Toast.makeText(this, "Can't DetectOrientation", Toast.LENGTH_LONG)
.show();
finish();
}
}
thanx提前。