Android Studio旋转时检测
我希望我的应用程序能够在应用程序从纵向旋转到横向时执行某些操作 我曾想过使用震动事件监听器,但我希望设备仅在倾斜一定程度时才能运行其功能。我认为最好的方法是让设备在从纵向切换到横向时进行监听 我想知道是否有这样的方法:Android Studio旋转时检测,android,android-studio,rotation,detect,Android,Android Studio,Rotation,Detect,我希望我的应用程序能够在应用程序从纵向旋转到横向时执行某些操作 我曾想过使用震动事件监听器,但我希望设备仅在倾斜一定程度时才能运行其功能。我认为最好的方法是让设备在从纵向切换到横向时进行监听 我想知道是否有这样的方法:onRotate()或oneterscape(),这样我只能在设备旋转时执行操作,类似这样: onEnterLandscape() { device.launchGoodies; } onEnterPortrait() { device.stopGoodies;
onRotate()
或oneterscape()
,这样我只能在设备旋转时执行操作,类似这样:
onEnterLandscape() {
device.launchGoodies;
}
onEnterPortrait() {
device.stopGoodies;
}
甚至
onDeviceRotate(90 degrees) {
device.launchGoodies;
}
onDeviceReturnToStart() {
devoce.stopGoodies;
}
我想知道是否有像这样的方法,或者其他更有效的方法
谢谢
Nathan您可以尝试使用OrientationEventListener并从onOrientationChanged()调用您的函数 或者,您可以使用一个标志来记住上一个方向,并在onCreate()中将其选中以进行更改(因为活动是在方向更改时重新创建的)