gpt4 book ai didi

安卓横屏180°旋转

转载 作者:行者123 更新时间:2023-11-30 00:54:50 27 4
gpt4 key购买 nike

我需要知道我的 Android 设备屏幕何时从一个横向旋转到另一个横向(rotation_90 到 rotation_270)。在我的 Android 服务中,我重新实现了 onConfigurationChanged(Configuration newConfig) 以了解设备的旋转。但是只有当设备从 ORIENTATION_PORTRAIT 旋转到 ORIENTATION_LANDSCAPE 时系统才会调用此方法,如果从 ORIENTATION_LANDSCAPE 旋转则不会调用此方法(90 °) 到另一个 ORIENTATION_LANDSCAPE (270°) !!

在这种情况下我如何被调用?谢谢。

最佳答案

您可以为您的 Activity 启用 OrientationEventListener。

OrientationEventListener mOrientationListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) {

@Override
public void onOrientationChanged(int orientation) {
Log.v(TAG, "Orientation changed to " + orientation);

if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
return;
}

int degrees = -1;
if (orientation < 45 || orientation > 315) {
Log.i(TAG, "Portrait");
} else if (orientation < 135) {
degrees = 90;
Log.i(TAG, "Landscape"); // This can be reverse landscape
} else if (orientation < 225) {
degrees = 180;
Log.i(TAG, "Reverse Portrait");
} else {
degrees = 270;
Log.i(TAG, "Reverse Landscape"); // This can be landscape
}
}
};

if (mOrientationListener.canDetectOrientation() == true) {
Log.v(TAG, "Can detect orientation");
mOrientationListener.enable();
} else {
Log.v(TAG, "Cannot detect orientation");
mOrientationListener.disable();
}

关于安卓横屏180°旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40344238/

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