<bdo id='1UtKS'></bdo><ul id='1UtKS'></ul>
<legend id='1UtKS'><style id='1UtKS'><dir id='1UtKS'><q id='1UtKS'></q></dir></style></legend>
    1. <i id='1UtKS'><tr id='1UtKS'><dt id='1UtKS'><q id='1UtKS'><span id='1UtKS'><b id='1UtKS'><form id='1UtKS'><ins id='1UtKS'></ins><ul id='1UtKS'></ul><sub id='1UtKS'></sub></form><legend id='1UtKS'></legend><bdo id='1UtKS'><pre id='1UtKS'><center id='1UtKS'></center></pre></bdo></b><th id='1UtKS'></th></span></q></dt></tr></i><div id='1UtKS'><tfoot id='1UtKS'></tfoot><dl id='1UtKS'><fieldset id='1UtKS'></fieldset></dl></div>

        <small id='1UtKS'></small><noframes id='1UtKS'>

        <tfoot id='1UtKS'></tfoot>

      1. 屏幕方向锁定

        Screen orientation lock(屏幕方向锁定)

          <bdo id='Rh1AY'></bdo><ul id='Rh1AY'></ul>
          1. <tfoot id='Rh1AY'></tfoot>

                <small id='Rh1AY'></small><noframes id='Rh1AY'>

              1. <i id='Rh1AY'><tr id='Rh1AY'><dt id='Rh1AY'><q id='Rh1AY'><span id='Rh1AY'><b id='Rh1AY'><form id='Rh1AY'><ins id='Rh1AY'></ins><ul id='Rh1AY'></ul><sub id='Rh1AY'></sub></form><legend id='Rh1AY'></legend><bdo id='Rh1AY'><pre id='Rh1AY'><center id='Rh1AY'></center></pre></bdo></b><th id='Rh1AY'></th></span></q></dt></tr></i><div id='Rh1AY'><tfoot id='Rh1AY'></tfoot><dl id='Rh1AY'><fieldset id='Rh1AY'></fieldset></dl></div>
                  <tbody id='Rh1AY'></tbody>

                  <legend id='Rh1AY'><style id='Rh1AY'><dir id='Rh1AY'><q id='Rh1AY'></q></dir></style></legend>
                • 本文介绍了屏幕方向锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  是否有可靠的方法在所有 Android 设备上锁定屏幕方向?下面的代码适用于我的 Nexus S 和其他手机,但由于某种原因,ROTATION_90 对应于 Xoom 上的 SCREEN_ORIENTATION_REVERSE_PORTRAIT.

                  Is there a reliable way to lock screen orientation on all Android devices? The code below works for my Nexus S and other phones, but for some reason ROTATION_90 corresponds to SCREEN_ORIENTATION_REVERSE_PORTRAIT on the Xoom.

                  有没有办法可靠地将旋转映射到方向?

                  Is there any way to reliably map rotation to orientation?

                  private void lockScreenOrientation() {
                      if (!mScreenOrientationLocked) {
                          final int orientation = getResources().getConfiguration().orientation;
                          final int rotation = getWindowManager().getDefaultDisplay().getOrientation();
                  
                          if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
                              if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                              }
                              else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                              }
                          }
                          else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
                              if (orientation == Configuration.ORIENTATION_PORTRAIT) {
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                              }
                              else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                              }
                          }
                  
                          mScreenOrientationLocked = true;
                      }
                  }
                  
                  private void unlockScreenOrientation() {
                      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
                      mScreenOrientationLocked = false;
                  }
                  

                  此代码旨在获取当前方向并将其锁定.方向被暂时锁定,然后释放给用户.

                  This code is meant to get the current orientation and lock it. The orientation is locked temporarily, and then released to the user.

                  推荐答案

                  这是我的解决方案,它适用于任何 Android SDK 的手机和平板电脑.

                  Here is my solution it works on phones and tablets in any Android SDK.

                  switch (getResources().getConfiguration().orientation){
                          case Configuration.ORIENTATION_PORTRAIT:
                              if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                              } else {
                                  int rotation = getWindowManager().getDefaultDisplay().getRotation();
                                  if(rotation == android.view.Surface.ROTATION_90|| rotation == android.view.Surface.ROTATION_180){
                                      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
                                  } else {
                                      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                                  }
                              }   
                          break;
                  
                          case Configuration.ORIENTATION_LANDSCAPE:
                              if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO){
                                  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                              } else {
                                  int rotation = getWindowManager().getDefaultDisplay().getRotation();
                                  if(rotation == android.view.Surface.ROTATION_0 || rotation == android.view.Surface.ROTATION_90){
                                      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                                  } else {
                                      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
                                  }
                              }
                          break;
                      }
                  

                  这篇关于屏幕方向锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How To Create a Rotating Wheel Control?(如何创建转轮控件?)
                  iOS 6 rotations: supportedInterfaceOrientations doesn#180;t work?(iOS 6 旋转:supportedInterfaceOrientations 不起作用?)
                  CABasicAnimation rotate returns to original position(CABasicAnimation 旋转返回原始位置)
                  How to avoid restarting activity when orientation changes on Android(如何在 Android 上的方向更改时避免重新启动活动)
                  UITabBarController Rotation Issues in ios 6(ios 6 中的 UITabBarController 旋转问题)
                  iOS: How to run a function after Device has Rotated (Swift)(iOS:设备旋转后如何运行函数(Swift))

                      <tbody id='qLKwj'></tbody>
                    <i id='qLKwj'><tr id='qLKwj'><dt id='qLKwj'><q id='qLKwj'><span id='qLKwj'><b id='qLKwj'><form id='qLKwj'><ins id='qLKwj'></ins><ul id='qLKwj'></ul><sub id='qLKwj'></sub></form><legend id='qLKwj'></legend><bdo id='qLKwj'><pre id='qLKwj'><center id='qLKwj'></center></pre></bdo></b><th id='qLKwj'></th></span></q></dt></tr></i><div id='qLKwj'><tfoot id='qLKwj'></tfoot><dl id='qLKwj'><fieldset id='qLKwj'></fieldset></dl></div>
                    <legend id='qLKwj'><style id='qLKwj'><dir id='qLKwj'><q id='qLKwj'></q></dir></style></legend>

                    • <small id='qLKwj'></small><noframes id='qLKwj'>

                        • <bdo id='qLKwj'></bdo><ul id='qLKwj'></ul>

                            <tfoot id='qLKwj'></tfoot>