java - android源码横竖屏设置问题
PHPz
PHPz 2017-04-18 09:54:31
0
1
664

求大神帮忙贴一下android4.4.2源码怎么让系统默认横屏,禁止转换成竖屏

PHPz
PHPz

学习是最好的投资!

membalas semua(1)
刘奇

Untuk menukar skrin mendatar dan menegak lalai Android, cuma ubah suai kod sumber di satu tempat.

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;  
            }  
        }  
}  

}

Ubah suai baris terakhir kod di atas dan tukar Surface.ROTATION_0 ke arah yang anda mahukan. Jika lebar dan tinggi berbeza, Surface.ROTATION_0 juga akan berbeza. Kerana kod bermula dengan:

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;  
    }  
}  

Rujukan: http://blog.csdn.net/wh_19910...

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan