Lock Screen Orientation in Android
Martin Belcher | 26th May 2010 | ||||||||
IntroThis article describes how to force the orientation of an Android view not to change ie screen not to rotate. How to lock the orientationIn theonCreateDialog(int) eventof the activity use thesetRequestedOrientation(int) methodto set the screen orientation to your chosen setting. The activity will stay in this orientation regardless of if the device is tilted or not.
How to detect the current orientationTo programmatically detect the current orientation of the activity use the following code snippet. Theorientation propertyof theConfiguration classreturns three possible values corresponding to Landscape, Portrait and Square.
Example : Locking rotation while performing an action.You might wish to disable the screen rotation whilst performing an action or by user command, to do this you need to combine the above samples to detect the current orientation and lock the display to that orientation.
Once your action has completed you may wish to enable screen rotation again, see the next section for an example on how to do this. How to re-enable screen rotationTo enable the orientation to be automatically changed on device tilt simply pass thesetRequestedOrientation(int) methodthe enumeration value for an unspecified orientation.
|
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer