gpt4 book ai didi

java - Android - 获取传感器横向方向

转载 作者:行者123 更新时间:2023-12-02 05:48:04 36 4
gpt4 key购买 nike

我正在玩游戏,方向是sensorLandscape。

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/GdxTheme" >
<activity
android:name="com.fainosag.marioskate.android.AndroidLauncher"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

现在,当我旋转手机时,我的游戏可以翻转。我遇到的问题是,当手机翻转时,加速度计值也会翻转..

如何找出 Android 横向方向是什么?

最佳答案

由于代表较低,我无法发表评论。 (之前刚刚转换为评论)

所以现在我知道你想要什么了,以前我不理解你。试试这个:

WindowManager mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);    

Display display = mWindowManager.getDefaultDisplay();
int rotation = display.getRotation();

使用 Surface.ROTATION_0(无旋转)、Surface.ROTATION_90Surface.ROTATION_180Surface 检查角度。 ROTATION_270

另请参见此处:http://developer.android.com/reference/android/view/Display.html#getRotation()在这里 http://developer.android.com/reference/android/view/Surface.html

关于java - Android - 获取传感器横向方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23857692/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com