How can I detect screen rotation?(如何检测屏幕旋转?)
问题描述
是否可以检测屏幕旋转?我的意思是 - 仅轮换,这与活动初始化与另一个活动有明显区别?
is it possible to detect screen rotation? I mean - rotation only, which is clearly distinguishable from activity initialization from another activity?
onXxx 方法似乎对此没有用,我尝试从 starting Intent
添加/删除 flag
(删除似乎没有反映,在旋转标志在那里),并尝试为清单中的活动添加 android:configChanges="orientation" ,但是 onConfigurationChanged
方法似乎每秒钟旋转一次...有线.
The onXxx methods seem not to be useful for this, I have tried adding/removing a flag
from the starting Intent
(the removing seems not to be reflected, on rotate the flag is there), and have tried adding android:configChanges="orientation" for the activity in the manifest, however the onConfigurationChanged
method seems to be called every second rotation... wired.
我想我遗漏了一些东西......但在其他相关线程中没有找到明确的解决方案.
I guess I am missing something... but haven't found clear solution in the other related threads.
有什么想法吗?
推荐答案
清单:
<activity android:name=".MyActivity" android:configChanges="screenSize|orientation|screenLayout|navigation"/>
活动:
@Override
public void onConfigurationChanged(Configuration newConfig)
{
Log.d("tag", "config changed");
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT)
Log.d("tag", "Portrait");
else if (orientation == Configuration.ORIENTATION_LANDSCAPE)
Log.d("tag", "Landscape");
else
Log.w("tag", "other: " + orientation);
....
}
也试试这个链接
如何检测屏幕旋转
这篇关于如何检测屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何检测屏幕旋转?


基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01