Android:垂直到水平旋转时暂停

发布于 2024-12-18 13:00:52 字数 90 浏览 2 评论 0原文

我怎么能做这样的事情 - 当你将屏幕从水平旋转到垂直应用程序设置在暂停时(并显示屏幕,据说你应该垂直旋转屏幕以继续等)?

或者我如何才能禁用屏幕旋转?

How could I make such thing - when you rotate screen from horizontal to vertical application set on pasue (and show screen where is said that you should to rotate screen in vertical to continue e.t.c)?

Or how I can just disable screen rotation?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄离 2024-12-25 13:00:52

屏幕方向设置为纵向或横向(具体取决于根据您的要求)在 Android 清单文件中。

然后根据需要监听加速度计事件。

查看此问题。

Set the screen orientation to portrait or landscape (depending on your requirements) in the Android manifest file.

Then listen to the Accelerometer events if required.

See this question.

墨落画卷 2024-12-25 13:00:52

我相信您正在寻找的答案是在 Android 应用程序的 Activity 生命周期中。

我找到了这个链接并立即浏览。
如何在 Android 上禁用方向更改?

编辑:从那里我可以看到,需要做的就是修改

  1. android 清单文件以将其包含在您的 Activity 中

    
    
  2. 在您的 MainActivity 中,应将其包含在内

    <前><代码>@Override
    公共无效onConfigurationChanged(配置newConfig){
    super.onConfigurationChanged(newConfig);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

I believe the answer you are looking for is in the activity life cycle of android apps.

I found this link and browsing it now.
How do I disable orientation change on Android?

edit: from there I can see that all that needs to be done is modify

  1. android manifest file to include this in your activity

    <activity android:name="MainActivity" 
        android:configChanges="keyboardHidden|orientation|screenSize">
    
  2. inside your MainActivity this should be included

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文