需求是屏幕每旋转到一定角度时,通过做一些操作,比如给webview发送消息

具体实现:
onCreate 方法里

//屏幕方向监听        OrientationEventListener mOrientationListener = new OrientationEventListener(this,                SensorManager.SENSOR_DELAY_NORMAL) {            @Override            public void onOrientationChanged(int orientation) {                // Log.v(DEBUG_TAG,"Orientation changed to " + orientation);                if (orientation > 350 || orientation < 10) { //0度                    orientation = 0;                    Point outSize = new Point();                    getWindowManager().getDefaultDisplay().getRealSize(outSize);                    int x = outSize.x;                    int y = outSize.y;                    System.out.println("x = " + x + ",y = " + y);                    System.out.println("xxxxxxxxx:竖屏 ");                    try {                        JSONObject obj = new JSONObject();                        obj.put("width", x);                        obj.put("height", y);                        obj.put("orientation", "portrait");                        JavascriptWXBridge.SrcChange(obj);                    } catch (JSONException e) {                        e.printStackTrace();                    }                } else if (orientation > 80 && orientation < 100) { //90度                    orientation = 90;                    Point outSize = new Point();                    getWindowManager().getDefaultDisplay().getRealSize(outSize);                    int x = outSize.x;                    int y = outSize.y;                    System.out.println("x = " + x + ",y = " + y);                    System.out.println("xxxxxxxxx:向右横屏 ");                    try {                        JSONObject obj = new JSONObject();                        obj.put("width", x);                        obj.put("height", y);                        obj.put("orientation", "landscape");                        JavascriptWXBridge.SrcChange(obj);                    } catch (JSONException e) {                        e.printStackTrace();                    }                } else if (orientation > 170 && orientation < 190) { //180度                    orientation = 180;                    Point outSize = new Point();                    getWindowManager().getDefaultDisplay().getRealSize(outSize);                    int x = outSize.x;                    int y = outSize.y;                    System.out.println("x = " + x + ",y = " + y);                    System.out.println("xxxxxxxxx:竖屏 ");                    try {                        JSONObject obj = new JSONObject();                        obj.put("width", x);                        obj.put("height", y);                        obj.put("orientation", "portrait");                        JavascriptWXBridge.SrcChange(obj);                    } catch (JSONException e) {                        e.printStackTrace();                    }                } else if (orientation > 260 && orientation < 280) { //270度                    orientation = 270;                    Point outSize = new Point();                    getWindowManager().getDefaultDisplay().getRealSize(outSize);                    int x = outSize.x;                    int y = outSize.y;                    System.out.println("x = " + x + ",y = " + y);                    System.out.println("xxxxxxxxx:向左横屏 ");                    try {                        JSONObject obj = new JSONObject();                        obj.put("width", x);                        obj.put("height", y);                        obj.put("orientation", "landscape");                        JavascriptWXBridge.SrcChange(obj);                    } catch (JSONException e) {                        e.printStackTrace();                    }                } else {                    return;                }            }        };

更多相关文章

  1. Android(安卓)OpenGL ES(五):GLSurfaceView
  2. android sqlite 操作 说明 记录
  3. Android(安卓)ApiDemos示例解析(117):Views->Focus->3. Circular
  4. Android(安卓)sensor 实用篇
  5. 10.ScrollView
  6. Android(安卓)多点触控(放大、缩小、旋转、位移)
  7. android按屏幕大小动态确定控件位置及大小
  8. android根据ListView内部Item最大长度来设置ListView的宽度
  9. android 屏幕保持唤醒 不锁屏

随机推荐

  1. 84 Android(安卓)Hnadler 封装下载图片工
  2. Get your hands on Android(安卓)Studio
  3. Security Enhancements for Android
  4. [RK3128][Android7.1]android鼠标按键板
  5. 47 Android(安卓)fragment 接口回调
  6. Android异步加载图片详解之方式二(3)
  7. Android(安卓)传感器学习(一)——指南针的
  8. android Service发送广播
  9. android Initializing a Build Environme
  10. Android(安卓)购物车的功能逻辑