Android 屏幕处于横屏状态 旋转180度界面切换显示

	public SreenOrientationListener mSreenOrientationListener;

	mSreenOrientationListener = new SreenOrientationListener(getContext());

 @Override
    protected void onResume() {
        super.onResume();
        mSreenOrientationListener.enable();
    }
@Override
    protected void onPause() {
        super.onPause();

        mSreenOrientationListener.disable();
    }

/**
     * 屏幕旋转
     * */
    class SreenOrientationListener extends OrientationEventListener {

        public SreenOrientationListener(Context context) {
            super(context);
        }

        @Override
        public void onOrientationChanged(int orientation) {
            if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
                return; // 手机平放时,检测不到有效的角度
            }
            // 只检测是否有四个角度的改变
            if (orientation > 350 || orientation < 10) {
                // 0度:手机默认竖屏状态(home键在正下方)
                orientation = 0;
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                Log.i("orientation","orientation"+orientation);
            } else if (orientation > 80 && orientation < 100) {
                // 90度:手机顺时针旋转90度横屏(home建在左侧)
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                Log.i("orientation","orientation"+orientation);
            } else if (orientation > 170 && orientation < 190) {
                // 手机顺时针旋转180度竖屏(home键在上方)
                orientation = 180;
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                Log.i("orientation","orientation"+orientation);
            } else if (orientation > 260 && orientation < 280) {
                // 手机顺时针旋转270度横屏,(home键在右侧)
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                Log.i("orientation","orientation"+orientation);
            }
        }
    }



ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED,  
       ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,  
       ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,  
       ActivityInfo.SCREEN_ORIENTATION_USER,  
       ActivityInfo.SCREEN_ORIENTATION_BEHIND,  
       ActivityInfo.SCREEN_ORIENTATION_SENSOR,  
       ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,  
       ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE,  
       ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT,  
       ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE,  
       ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT,  
       ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR,





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值