我有一個方向在android中的問題。設備方向是我在AndroidManifest.xml文件中設置的橫向。Android設備的方向是風景,但傳感器的行爲像方向是肖像
android:screenOrientation="landscape"
此外,我手持設備的橫向,所以一切(佈局,視圖等)是在橫向模式,因爲我希望它是。但只有當我以縱向方式握住設備時,它纔會給我提供我需要的價值。
我修改了一些代碼,從互聯網和它適用於HTC 3D EVO的Nexus 7和三星Galaxy S3,但不是在Galaxy平板10" 。
我發現這個職位。 Android Orientation Sensor Different for Different Devices? 接受的答案建議使用getRotation()和remapCoordinateSystem()方法,但沒有提到如何。
這是怎麼了結束了。
SensorManager.getRotationMatrix(Rmat, Imat, gData, mData);
SensorManager.remapCoordinateSystem(Rmat, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, R2);
// Orientation isn't as useful as a rotation matrix, but
// we'll show it here anyway.
SensorManager.getOrientation(R2, orientation);
float incl = SensorManager.getInclination(Imat);
FontTextView pitchText = (FontTextView)findViewById(R.id.pitch_text);
if((int)(orientation[1]*90) <= -110 && !newQuestionIsActive) {
newQuestionIsActive = true;
pitchText.setText("Bring new question");
}
else if(Math.abs((int)(orientation[2]*90)) <= 200 && (int)(orientation[1]*90) >= -30 && newQuestionIsActive) {
newQuestionIsActive = false;
pitchText.setText("Not Correct!");
}
else if(Math.abs((int)(orientation[2]*90)) > 200 && (int)(orientation[1]*90) >= -30 && newQuestionIsActive) {
newQuestionIsActive = false;
pitchText.setText("Congratulations!");
}
現在我怎麼利用克這個代碼中的etRotation()?並可能是一個簡短的解釋,將不勝感激爲什麼那些提到3設備工作正常,但不是銀河平板電腦。
關於這個問題android文檔說;
最後,如果您的應用傳感器數據匹配到屏幕上的 顯示, 您需要使用getRotation()方法來確定屏幕旋轉,然後用 remapCoordinateSystem()方法來MAP傳感器座標屏幕座標。 即使您的清單指定僅肖像顯示,您也需要執行此操作。
http://android-developers.blogspot.com/2010/09/one-screen-turn-deserves-another.html
此解決方案中的R2是什麼? – hubatish
@hubatish R2是新的矩陣,您應該將其用作SensorManager.getOrientation()api的輸入矩陣,而不是Rmat。 – dragonfly