0

How to get it? In my XML file I use the only portrait orientation for my activity.

android:configChanges="keyboard|keyboardHidden|orientation|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden"

and onConfigurationChanged and does not work for orientation.

Upd currently I used:

@Override
    public void onSensorChanged(SensorEvent event) {
        x = event.values[0];
        y = event.values[1];
    }

    private PictureOrientation getLastOrientation() {
        MyPictureOrientation orient;
        if (x >= -5 && x < 5) {
            if (y > 0) {
                orient = PORTRAIT;
            } else {
                orient = PORTRAIT_REV;
            }
        } else {
            if (x >= -10 && x < -5) {
                orient = LAND_RIGHT;
            } else {
                orient = LAND_LEFT;
            }
        }

        return orient;
    }
4

3 に答える 3

0

次のコードを使用して、現在の向きを取得できます。

getResources().getConfiguration().orientation
于 2012-11-22T08:48:08.893 に答える