简体   繁体   English

方向锁定

[英]Orientation Lock

How can I prevent my app form rotating. 如何防止我的应用程序表单旋转。 I want it so if the user is in portrait mode, the app will always be in portrait mode, and if they start the app in landscape the app will always be in lanscape (until the app is closed and started again) 我想要它,所以如果用户处于纵向模式,应用程序将始终处于纵向模式,如果他们以横向启动应用程序,应用程序将始终处于lanscape(直到应用程序关闭并再次启动)

public static void lockOrientation(Activity a) {
    if (a.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    } else {
        a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}

public static void unlockOrientation(Activity a) {
    a.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM