更改屏幕方向Android中没有重装活动重装、屏幕、方向、Android

2023-09-04 08:22:04 作者:賊船妳上嗎.

我想改变方向以编程方式在运行我的Andr​​oid应用程序,用code这几行:

I want to change the orientation programmatically while running my Android App, with these lines of code:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);  
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);

他们的工作,到目前为止,但主要的问题是,整个活动被重新装载时,屏幕方向改变了,我不希望出现这种情况。可能吗?谢谢你。

They work so far, but the main problem is that the whole activity is reloaded when the screen orientation changes, and I don't want that. Is it possible? Thanks.

编辑:好了,以后我当我发现我失踪了。我在configChanges财产必须还包括屏幕尺寸,所以有

android:configChanges="orientation|screenSize"

解决了整个事情。

推荐答案

请参阅编辑由@luisfer。对于那些针对安卓3.2及以上版本,你既需要

See the edit by @luisfer. For targeting Android 3.2 and above, you need BOTH

android:configChanges="orientation|screenSize"

http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange