更改屏幕方向Android中没有重装活动 [英] Change screen orientation in Android without reloading the activity

查看:148
本文介绍了更改屏幕方向Android中没有重装活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变方向以编程方式在运行我的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"

<一个href="http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange">http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange

这篇关于更改屏幕方向Android中没有重装活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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