3

I made an app using accelerometer but problem is whenever it detects rotation of the screen, it goes to main menu.

I used following code to disable rotation but it still detects the rotation action and goes to mainmenu although it does not become landscape mode anymore.

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

How can I prevent this rotation detection?

4

3 に答える 3

7

AndroidManifest.xmlandroid:screenOrientation="portrait"ファイルのアクティビティ タグ内に配置します。その属性は、この特定のアクティビティが常に縦向きモードで実行される必要があることを定義するため、Android は回転時に画面の向きを変更しようとしません。

于 2012-01-05T11:26:44.280 に答える
2

あなたも追加したいでしょう

android:configChanges="keyboard|keyboardHidden|orientation"

キーボードが表示または非表示になったときの再起動を防ぐため。

これを使用するandroid:screenOrientation="portrait"場合、ゲームを横向きと縦向きの両方のモードで動作させたい場合は、削除することもできます。libgdx wiki を参照してください: https://code.google.com/p/libgdx/wiki/ApplicationConfiguration#The_.xml_File

于 2013-09-05T20:36:34.660 に答える
2

キミの答えは正しいですが、ゲームを Amazon デバイスでも実行したい場合は、「screenSize」という値を追加する必要があります。したがって、結果は次のようになります。

android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

于 2014-04-02T21:53:44.127 に答える