如何避免活动的再创作旋转时,同时尊重方向锁定? [英] How to avoid activity re-creation when being rotated, while also respecting orientation lock?

查看:167
本文介绍了如何避免活动的再创作旋转时,同时尊重方向锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次设备正在旋转,Android将破坏当前的活动,并以新配置重新创建它。

Each time the device is being rotated, Android will destroy the current activity and re-create it with the new configuration.

这是简单的方法来避免活动的再创造是通过增加的 configChanges 值清单(屏幕尺寸和方向我记得)。

An easy way to avoid activity re-creation is by adding "configChanges" values to the manifest ("screenSize" and "orientation" as I recall).

如果您使用configChanges属性,应用程序将不会尊重方向锁定功能,部分(或全部?)Android设备都有,其中prevent从当屏幕旋转而旋转任何东西。

If you use the "configChanges" attribute, the app won't respect the orientation lock feature that some (or all?) Android devices have, which prevent anything from being rotated when the screen is being rotated.

我试过打 screenOrientation 属性值,但他们没有达到我想要的东西。

I tried playing with the "screenOrientation" attribute values, yet none of them achieved what I wanted.

我怎样才能prevent被重新创建时,屏幕改变其方向,同时也尊重方向锁的用户preference活动?

How can I prevent the activity from being re-created when the screen changes its orientation, while also respecting the user preference of orientation-lock?

难道或许可能得到这个preference的价值,这样我就可以让活动锁定其方向时,它被设置?

Is it perhaps possible to get the value of this preference, so that I could let the activity lock its orientation when it's being set?

推荐答案

OK,没关系。我想我只是错过了正确的:

OK, never mind. I think I just missed the correct one:

安卓screenOrientation =用户

android:screenOrientation="user"

连同其他configChanges值,这个完美的作品。

Together with the other configChanges values, this works perfectly.

这篇关于如何避免活动的再创作旋转时,同时尊重方向锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆