`
7090
  • 浏览: 273539 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

(转)Android横竖屏切换

阅读更多

关于Android中Activity的横竖屏切换问题可以通过AndroidManifest.xml文件中的Activity来配置:android:screenOrientation =["unspecified" | "user" | "behind" |
"landscape" | "portrait" |
"sensor" | "nonsensor"]screenOrientation 用来指定Activity的在设备上显示的方向,每个值代表如下含义:

"unspecified" 默认值 由系统来判断显示方向.判定的策略是和设备相关的,所以不同的设备会有不同的显示方向.
"landscape" 横屏显示(宽比高要长)
"portrait" 竖屏显示(高比宽要长)
"user" 用户当前首选的方向
"behind" 和该Activity下面的那个Activity的方向一致(在Activity堆栈中的)
"sensor" 有物理的感应器来决定。如果用户旋转设备这屏幕会横竖屏切换。
"nosensor" 忽略物理感应器,这样就不会随着用户旋转设备而更改了 ( "unspecified"设置除外 )。

 

1、不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次
2、设置Activity的android:configChanges="orientation"时,切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次
3、设置Activity的android:configChanges="orientation|keyboardHidden"时,切屏不会重新调用各个生命周期,只会执行onConfigurationChanged方法

 

参考:http://www.chengyunfeng.com/2010/04/switch-horizontal-and-vertical-screen-android-program

http://blog.csdn.net/kepoon/archive/2011/03/18/6258070.aspx

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics