简体   繁体   English

Android:根据设备的屏幕尺寸更改方向更改选项

[英]Android: Change orientation change options depending on screen size of device

Is there a way for the Android Manifest to be different depending on screen size? Android Manifest是否有办法根据屏幕大小而有所不同? I want android:configChanges to not include "orientation" if the device is a tablet (ie xlarge screen size) 我希望android:configChanges如果设备是平板电脑,则不包含“方向”(即xlarge屏幕尺寸)

Moreover, I want android:screenOrientation to be different depending on which device is used. 此外,我希望android:screenOrientation根据所使用的设备而有所不同。 Any advice? 有什么建议吗?

I know of no way to do something that complex in AndroidManifest.xml, however you can do it programmatically via Activity.setRequestedOrientation() method. 我不知道如何在AndroidManifest.xml中执行复杂的操作,但是您可以通过Activity.setRequestedOrientation()方法以编程方式进行操作。 It's easy enough to wrap this in a utility class and then query your environment accordingly. 将其包装在实用程序类中,然后相应地查询您的环境非常容易。 One word of warning though - if calling this method does actually result in an orientation change, your Activity's onCreate() will be called a second time. 不过要提一个警告-如果调用此方法确实导致方向改变,那么将再次调用Activity的onCreate() Another thing that might come in handy if you choose to go this route, if the following evaluates to true: 如果您选择走这条路线,并且以下内容为真,那么另一件事可能会派上用场:

if((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {...}

Then you are on a tablet device, or at least your layouts are being loaded from layout-large (if you have one). 然后,您在平板电脑设备上,或者至少从大布局(如果有)加载布局。 Puting it all together, the following would lock a tablet into landscape mode and phones into portrait mode: 综上所述,以下操作会将平板电脑锁定为横向模式,而手机锁定为纵向模式:

      if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
         return true;
      } else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {
         return false;
      } else if ((cfg.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {
         return false;
      } else {
         // Assume that all other ratings are tablets or possibly even larger devices; there is an
         // extra large spec however it is only available OS versions 3.x and above so there is no clean way to query for this state.
         return true;
      }

please have a look at this ......... supports-screens android:resizeable=["true"| 请看看这个.........支持屏幕android:resizeable = [“ true” | "false"] android:smallScreens=["true" | “ false”] android:smallScreens = [“ true” | "false"] android:normalScreens=["true" | “ false”] android:normalScreens = [“ true” | "false"] android:largeScreens=["true" | “ false”] android:largeScreens = [“ true” | "false"] android:xlargeScreens=["true" | “ false”] android:xlargeScreens = [“ true” | "false"] android:anyDensity=["true" | “ false”] android:anyDensity = [“ true” | "false"] android:requiresSmallestWidthDp="integer" android:compatibleWidthLimitDp="integer" android:largestWidthLimitDp="integer ............... It will be Handle your screen “ false”] android:requiresSmallestWidthDp =“ integer” android:compatibleWidthLimitDp =“ integer” android:largestWidthLimitDp =“ integer ......它将处理您的屏幕

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

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