2011-08-04 82 views
2

我想知道什么时候设备大概需要改变方向,当我们旋转它。在我的应用程序中,当我旋转手机设备时,大约需要1到2秒的时间来旋转屏幕。现在我的问题是,这是正常跨度还是延迟跨度。所以我可以相应地处理它。方向更改默认时间延迟...?

在此先感谢。

+1

这就是我的想法,但有人告诉我你的方向变化很慢,这就是为什么我认为,我更好地向人们咨询Stackoverflow。我们可以旋转应用程序而不会破坏活动.. ????? – Rasel

+0

@Rasel ...绝对 –

+1

是的,你可以。 http://developer.android.com/resources/articles/faster-screen-orientation-change.html哦。你还必须阅读关于onConfigurationChanged http://developer.android.com/guide/topics/resources/runtime-changes.html –

回答

0

add在清单文件中添加android:configChanges="orientation|screenSize"。例如

<activity 
      android:name="example.pangasinantranslator.MainActivity"    
      android:configChanges="orientation|screenSize" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
1

从一个小小的代码研究,它看起来至少需要200毫秒才能旋转视图。这种延迟是为了确保设备方向的改变是有意的。

代码从WindowOrientationListener.java片断供参考:

// The number of milliseconds for which the device posture must be stable 
// before we perform an orientation change. If the device appears to be rotating 
// (being picked up, put down) then we keep waiting until it settles. 
private static final int SETTLE_TIME_MIN_MS = 200; 
当朝向改变你当前活动的破坏,reloaded.So你可以认为它需要时间从什么需要从onCreate方法开始
+0

“这种延迟是为了确保方向的改变是有意的。”这没有任何意义。 – Biu

+1

@Biu,在用户将设备放在桌子上或拿起桌子等情况下,设备的方向可能会短暂改变,但用户可能并不打算改变视图的方向。为防止在这种情况下定位视图,这种情况非常普遍,代码确保在旋转视图以补偿设备的新方向之前,设备的新/改变的方向在一段时间内保持稳定('SETTLE_TIME_MIN_MS') 。希望这是有道理的。 – MemoryLeak

+0

@Biu,对于这个逻辑的代码级别的理解,请参考WindowOrientationListener.java的'onSensorChanged()'方法(https://android.googlesource.com/platform/frameworks/base/+/android-4.0.4_r1/芯/ JAVA /机器人/视图/ WindowOrientationListener.java) – MemoryLeak