sách gpt4 ai đã đi

安卓横屏180°旋转

In lại 作者:行者123 更新时间:2023-11-30 00:54:50 28 4
mua khóa gpt4 Nike

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

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

1 Câu trả lời

您可以为您的 Activity 启用 OrientationEventListener。

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

@Ghi đè
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");
} khác {
degrees = 270;
Log.i(TAG, "Reverse Landscape"); // This can be landscape
}
}
};

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

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

28 4 0
Bài viết được đề xuất: 安卓 Pdf 查看器 FileNotFoundException
Bài viết được đề xuất: android - 如何删除 Gradle 冲突
Bài viết được đề xuất: c++ 如何处理返回 NULL 或 std::string 的方法?
Bài viết được đề xuất: Android 客户端使用 Spring 连接到 websocket 服务器
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com