英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论