是否可以检测屏幕旋转?我的意思是 - 仅轮换,这与活动初始化与另一个活动有明显区别?
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);
....
}
也试试这个链接
如何检测屏幕旋转
这篇关于如何检测屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!