我如何可以检测屏幕旋转? [英] How can I detect screen rotation?

查看:146
本文介绍了我如何可以检测屏幕旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是它可以检测屏幕旋转?只有旋转,这是从另一个活动活动初始化

清晰可辨 - 我的意思吗?

该onXxx方法似乎不是这个有用的,我也尝试添加/删除标志启动意图(去除似乎并没有得到体现,在旋转的标志那里),并尝试添加的android:configChanges =方向在清单中的活动,但是 onConfigurationChanged 方法好像是叫每个第二旋转......有线。

我想我失去了一些东西......但还没有找到明确的解决方案中的其他相关的线程。

任何想法?所有的帮助是AP preciated!
问候


解决方案

 的android:configChanges =方向|键盘@覆盖
公共无效onConfigurationChanged(配置NEWCONFIG)
{
Log.d(标签,配置化);
super.onConfigurationChanged(NEWCONFIG);INT方向= newConfig.orientation;
如果(方向== Configuration.ORIENTATION_PORTRAIT)
    Log.d(标签,人像);
否则,如果(方向== Configuration.ORIENTATION_LANDSCAPE)
    Log.d(标签,山水);
其他
    Log.w(标签,其他+方向);....
}

尝试此链接还

如何检测屏幕旋转

is it possible to detect screen rotation? I mean - rotation only, which is clearly distinguishable from activity initialization from another activity?

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.

Any ideas? All help is appreciated! Regards

解决方案

android:configChanges="orientation|keyboard"

@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);

....
}

try this link also

How do I detect screen rotation

这篇关于我如何可以检测屏幕旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆