【发布时间】:2012-02-29 23:53:27
【问题描述】:
这是一个检测屏幕旋转事件并决定保留或更改屏幕方向的伪代码。
public boolean onOrientationChanges(orientation) {
if(orientation == landscape)
if(settings.get("lock_orientation"))
return false; // Retain portrait mode
else
return true; // change to landscape mode
return true;
}
如何在 Android 中制作类似的东西?
编辑: 我实际上正在寻找在哪里处理方向更改的答案。我不想通过添加 screenOrientation="portrait" 来修复方向。
我需要一些类似于 onConfigurationChanges() 的东西,我可以在其中处理方向,但不需要我手动重绘视图。
【问题讨论】:
-
您不需要拦截请求然后允许或拒绝它。您可以提前锁定或释放方向。这种方法还有更多的选择,比如锁定时是否允许 180 度旋转。请在下面阅读我的答案,而不是选择的答案。
标签: android runtime orientation