让activity保持横屏或者竖屏

  • Post author:
  • Post category:其他


让activity保持横屏或者竖屏有两种方式,一种是在activity的AndroidManifest.xml中设置

    <activity
            android:name=".MainActivity"
            android:label="@string/app_name"

        <!--设置横屏 竖屏为portrait-->
android:screenOrientation="landscape" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

在Activity代码中设置:

     //横屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        //竖屏
    //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

转载于:https://www.cnblogs.com/jonzone/p/4615061.html