android OrientationEventListener监测指定的屏幕旋转角度
2018-01-03 14:14
197 查看
关于OrientationEventListener监测指定的屏幕旋转角度,可以从自己的开发的场景不同进行使用;
不多说了,直接上代码;
Android屏幕旋转使用http://blog.csdn.net/xiao_yuanjl/article/details/78960427
不多说了,直接上代码;
public class MainActivity extends Activity { OrientationEventListener mOrientationListener; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mOrientationListener = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL) { @Override public void onOrientationChanged(int orientation) { if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) { return; //手机平放时,检测不到有效的角度 } //可以根据不同角度检测处理,这里只检测四个角度的改变 if (orientation > 350 || orientation < 10) { //0度 orientation = 0; } else if (orientation > 80 && orientation < 100) { //90度 orientation = 90; } else if (orientation > 170 && orientation < 190) { //180度 orientation = 180; } else if (orientation > 260 && orientation < 280) { //270度 orientation = 270; } else { return; } } }; if (mOrientationListener.canDetectOrientation()) { mOrientationListener.enable(); } else { mOrientationListener.disable(); } } @Override protected void onDestroy() { super.onDestroy(); mOrientationListener.disable(); } }
Android屏幕旋转使用http://blog.csdn.net/xiao_yuanjl/article/details/78960427
相关文章推荐
- Cocos2D旋转炮塔到指定角度(二)
- Box2D C++ 教程-旋转到指定角度
- 【Unity3d基础】Unity3d 中如何旋转一张2D图片到指定角度
- Cocos2D旋转炮塔到指定角度(二)
- BOX2D 自然的旋转到一个指定角度
- Android之随用户的角度旋转屏幕
- iOS指定页面屏幕旋转,手动旋转(某app实现功能全过程)
- Android--获取当前屏幕的旋转角度
- BOX2D 自然的旋转到一个指定角度
- Cocos2D旋转炮塔到指定角度(三)
- Cocos2D旋转炮塔到指定角度(三)
- Box2D C++ 教程-旋转到指定角度
- Cocos2D旋转炮塔到指定角度(三)
- box2d 旋转到指定角度
- 屏幕常亮及旋转的角度等-Android
- OX2D 自然的旋转到一个指定角度
- UI 第三课 ⼀、自定义视图 二、视图控制器指定⾃自定义View 三、检测屏幕旋转 四、处理内存警告 五、容器视图控制器
- 屏幕旋转角度的处理
- [置顶] iOS如何指定某个页面可以旋转屏幕,其余控制器都正常竖屏
- java图片旋转指定角度