在 Android 中旋转屏幕时不执行任何操作。

huangapple go评论75阅读模式
英文:

Do nothing when rotating the screen in android

问题

我正在开发一个相机应用程序,但当我改变方向时,活动会被重新创建。问题是它需要大约2秒的时间重新启动,这看起来很糟糕,因为图像会有一个暂停。这就是为什么我希望它能够与默认的相机应用程序有类似的行为,即在旋转屏幕时只旋转图标,不会出现不愉快的暂停。

我尝试过使用 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);,但是getResources().getConfiguration().orientation 总是返回1(竖屏),所以我希望有类似于 SCREEN_ORIENTATION_PORTRAIT 的行为,即在旋转屏幕时什么都不做。

但是我需要检测屏幕是否已经旋转(以便我可以控制接下来应该发生什么)。

英文:

I am working on a camera application, but when I change the orientation the activity is rebuilt, the problem is that it takes about 2 seconds to start all over again and that looks very bad because there is a pause in the image, that's why I want it have a similar behavior to the default camera application that when rotating the screen simply rotates the icons, no unpleasant pauses are seen ...

I tried setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); but
getResources().getConfiguration().orientation it always returns 1 (portrait), so I want something similar to the behavior of SCREEN_ORIENTATION_PORTRAIT which does nothing when rotating the screen.

But I need detect that the screen was rotated (so I can control what should happen)

答案1

得分: 1

你可以在清单文件中的活动中设置 android:configChanges="orientation" 来自行处理配置更改。这样,当屏幕旋转时,你的活动就不会被销毁。你可以在这里阅读更多关于配置更改的信息。

然后,你还可以重写 onConfigurationChanged 方法来检测手机的旋转。

英文:

You could handle configuration changes yourself by setting android:configChanges="orientation" in your activity in your manifest. Then your activity won't be destroyed when the screen is rotated. You can read more about configChanges here.

Then you can also override onConfigurationChanged to detect the rotation of the phone.

huangapple
  • 本文由 发表于 2020年9月15日 23:05:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63904694.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定