简体   繁体   English

Android锁屏旋转

[英]Android lock screen rotation

I know that I can set the screen layout to portrait or landscape in my activity's xml tag in the manifest to prevent the screen from rotation. 我知道可以在清单的活动的xml标签中将屏幕布局设置为纵向或横向,以防止屏幕旋转。

I have an app which shall run on a phone and on a tablet. 我有一个可以在手机和平​​板电脑上运行的应用程序。 On the tablet I want to have landscape and on the phone I want to have portrait mode. 在平板电脑上,我想要横向放置;在手机上,我想要纵向放置。 How can I do this configuration? 我该如何配置? (And of course when the device rotates the screen shall not). (当然,当设备旋转屏幕时也不会)。

For check whether its a tab or not, you can use this simple method: 要检查其是否为选项卡,可以使用以下简单方法:

public boolean isTablet(Context context){
boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
return (xlarge || large);
}

OR 要么

      public static boolean isTablet(Context context) {
      return (context.getResources().getConfiguration().screenLayout
        & Configuration.SCREENLAYOUT_SIZE_MASK)
        >= Configuration.SCREENLAYOUT_SIZE_LARGE;
      }

Both are helpful for you. 两者都对您有帮助。

For more information, check this conversation. 有关更多信息,请检查此对话。

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

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