如何改变android默认的横竖屏,修改源码一个地方就可以了。


 public int rotationForOrientationLw(int orientation, int lastRotation,            boolean displayEnabled) {        if (mPortraitRotation < 0) {            // Initialize the rotation angles for each orientation once.            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))                    .getDefaultDisplay();            if (d.getWidth() > d.getHeight()) {                mPortraitRotation = Surface.ROTATION_90;                mLandscapeRotation = Surface.ROTATION_0;                mUpsideDownRotation = Surface.ROTATION_270;                mSeascapeRotation = Surface.ROTATION_180;            } else {                mPortraitRotation = Surface.ROTATION_0;                mLandscapeRotation = Surface.ROTATION_90;                mUpsideDownRotation = Surface.ROTATION_180;                mSeascapeRotation = Surface.ROTATION_270;            }        }{Log.i(TAG, "MediaPlayer.is not PlayingVideo");        synchronized (mLock) {            switch (orientation) {                case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:                    //always return portrait if orientation set to portrait                    //return mPortraitRotation;                    return mUpsideDownRotation;                case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:                    //always return landscape if orientation set to landscape                    return mLandscapeRotation;                case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:                    //always return portrait if orientation set to portrait                    //return mUpsideDownRotation;return mPortraitRotation;                case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:                    //always return seascape if orientation set to reverse landscape                    return mSeascapeRotation;                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:                    //return either landscape rotation based on the sensor                    mOrientationListener.setAllow180Rotation(                            isLandscapeOrSeascape(Surface.ROTATION_180));                    return getCurrentLandscapeRotation(lastRotation);                case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:                    mOrientationListener.setAllow180Rotation(                            !isLandscapeOrSeascape(Surface.ROTATION_180));                    return getCurrentPortraitRotation(lastRotation);            }            mOrientationListener.setAllow180Rotation(                    orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR                    || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);            // case for nosensor meaning ignore sensor and consider only lid            // or orientation sensor disabled            //or case.unspecified            if (mLidOpen) {                return mLidOpenRotation;            } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) {                return mCarDockRotation;            } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) {                return mDeskDockRotation;            } else {                if (useSensorForOrientationLp(orientation)) {                    return mOrientationListener.getCurrentRotation(lastRotation);                }                return Surface.ROTATION_0;            }        }}    }

修改上面倒数一行代码把return Surface.ROTATION_0改为你要的方向,记得这个要和上面的匹配,宽高不同,Surface.ROTATION_0也不同。因为代码开头就有

        if (mPortraitRotation < 0) {            // Initialize the rotation angles for each orientation once.            Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))                    .getDefaultDisplay();            if (d.getWidth() > d.getHeight()) {                mPortraitRotation = Surface.ROTATION_90;                mLandscapeRotation = Surface.ROTATION_0;                mUpsideDownRotation = Surface.ROTATION_270;                mSeascapeRotation = Surface.ROTATION_180;            } else {                mPortraitRotation = Surface.ROTATION_0;                mLandscapeRotation = Surface.ROTATION_90;                mUpsideDownRotation = Surface.ROTATION_180;                mSeascapeRotation = Surface.ROTATION_270;            }        }





更多相关文章

  1. Anko:Android 代码动态布局的新方案
  2. Android Jetpack之Lifecycle的源码分析
  3. Android 获取系统权限的代码
  4. Android 源码启动虚拟机经验
  5. Android MediaScannerJNI源码详解
  6. 编译代码报出Android library projects cannot be launched错误
  7. 解决Eclipse3.6中Android 代码自动补全卡死的问题
  8. 2.在服务器上使用 gradle 打包 android 源码
  9. android 下测试网络的丢包率和延迟 的代码

随机推荐

  1. 【图解数据结构】 一组动画彻底理解选择
  2. 每天一算:Valid Parentheses
  3. 每天一算:Reverse String
  4. 【图解数据结构】 一组动画彻底理解快速
  5. 每天一算:Evaluate Reverse Polish Notati
  6. 每天一算:Remove Linked List Elements
  7. 【图解数据结构】 一组动画彻底理解插入
  8. 每天一算:Binary Tree Preorder Traversal
  9. 每天一算:Swap Nodes in Pairs
  10. ubuntu 编译 Android(安卓)出现的若干错