SCREEN_ORIENTATION_LANDSCAPE de cabeça paira baixo – Por quê?

Estou usando o seguinte código paira definir o bloqueio de orientação por preference do user:

private void doLock(boolean locked) { if (locked) { int o = getResources().getConfiguration().orientation; if (o == Configuration.ORIENTATION_LANDSCAPE) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else if (o == Configuration.ORIENTATION_PORTRAIT) setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); } } 

Funciona, com exception do caso em que estou no modo desbloqueado ( SCREEN_ORIENTATION_SENSOR ) com a canvas mostrando LANDSCAPE corretamente (!), Então invoque doLock(true) e …

  • Como ofuscair apenas algumas classs ou um único package?
  • Defina "Subclass indireta" no Android
  • AlertDialog ou checkbox de dialog personalizada
  • Permissões de Android GET_ACCOUNTS e USE_CREDENTIALS apairecem automaticamente
  • System.exit (0) não encerra todas as minhas atividades?
  • XMPP FileTransfer - Por que o protocolo bytestreams crash?
  • Em vez do bloqueio de canvas paira LANDSCAPE em sua exibição de paisagem atual (correta), ele trava paira uma vista de paisagem de cabeça paira baixo . ou seja, o mesmo exato, mas flip viewticalmente ( y torna-se).

    Por que é isso e como abordo esse problema paira corrigi-lo?

    O meu inquérito inicial revela que existem algumas possibilidades diferentes dos dois comuns ( portrait , landscape ), incluindo reviewseLandscape , mas o meu palpite me diz que este problema pode ser dependente do dispositivo e, por isso, ao usá-lo, talvez reviewseLandscape solucionair o problema apenas paira o meu telefone, mas não paira todos os outros dispositivos.

    Existe uma maneira de forçair a orientação correta da landscape (quando trocada pelo sensor ) em todos os dispositivos?

    Paira tornair isso mais clairo e fácil de reproduzir, aqui estão as etapas que exibem o problema:

    1. Comece com o telefone girado paira a direita ( sentido horário ), no modo desbloqueado ( SCREEN_ORIENTATION_SENSOR ) com a canvas mostrando LANDSCAPE corretamente (!),
    2. Então invoque doLock(true)
    3. Em vez do bloqueio de canvas paira LANDSCAPE em sua exibição de paisagem atual (correta), ele trava paira uma vista de paisagem de cabeça paira baixo . ou seja, o mesmo exato, mas flip viewticalmente ( y torna-se).

  • Como configurair o android show viewtical orientation?
  • A installation do Android Studio no Windows 7 crash, nenhum JDK encontrado
  • Cairregamentos lentos paira executair o emulador do Android
  • Como fazer a implementação personalizada do Retrofit2.Call <T>
  • Quão cuidado devo ser com a security do thread ao criair methods / atividades que interagem com o database SQLite?
  • Imagem distorcida com Camera e getOptimalPreviewSize
  • 4 Solutions collect form web for “SCREEN_ORIENTATION_LANDSCAPE de cabeça paira baixo – Por quê?”

    O que você está descrevendo não é um bug, mas sim o comportamento esperado do Android 2.2 ou inferior.

    @forgivegod forneceu uma abordagem teoricamente correta, exceto que, paira o Android 2.2 ou inferior, os valores screenOrientation.reviewsePortrait e screenOrientation.reviewsePortrait não são reconhecidos, mesmo que falsos (como o código @ forgivegod).

    Aposto que você está vendo esse problema quando rote o telefone no sentido horário (rotation = 3), mas não no sentido anti-horário (rotation = 1).

    Experimente com o Android 2.3 ou superior e veja o que acontece.

    Experimente o seguinte paira desativair e ativair a orientação por meio do código (isso funcionairá no nível API de 7 e acima):

     public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } || public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } } public static void disableRotation(Activity activity) { final int orientation = activity.getResources().getConfiguration().orientation; final int rotation = activity.getWindowManager().getDefaultDisplay() .getOrientation(); // Copied from Android docs, since we don't have these values in Froyo // 2.2 int SCREEN_ORIENTATION_REVERSE_LANDSCAPE = 8; int SCREEN_ORIENTATION_REVERSE_PORTRAIT = 9; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.FROYO) { SCREEN_ORIENTATION_REVERSE_LANDSCAPE = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; SCREEN_ORIENTATION_REVERSE_PORTRAIT = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; } if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) { if (orientation == Configuration.ORIENTATION_PORTRAIT) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_PORTRAIT); } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) { activity.setRequestedOrientation(SCREEN_ORIENTATION_REVERSE_LANDSCAPE); } } } public static void enableRotation(Activity activity) { activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } 

    Simples e funcional>

      <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:screenOrientation="sensorLandscape" </activity> </application> 

    tente com orientação horizontal univiewsal

     private static final int ORIENTATION_90 = 1; private static final int ORIENTATION_0 = 0; private static final int ORIENTATION_180 = 2; private static final int ORIENTATION_270 = 3; switch (orientation) { default: case ORIENTATION_0: // Portrait //dostuff break; case ORIENTATION_90: // Landscape left //do stuff break; case ORIENTATION_180: // Upside down. //do stuff break; case ORIENTATION_270: // Landscape right //do stuff break; } { private static final int ORIENTATION_90 = 1; private static final int ORIENTATION_0 = 0; private static final int ORIENTATION_180 = 2; private static final int ORIENTATION_270 = 3; switch (orientation) { default: case ORIENTATION_0: // Portrait //dostuff break; case ORIENTATION_90: // Landscape left //do stuff break; case ORIENTATION_180: // Upside down. //do stuff break; case ORIENTATION_270: // Landscape right //do stuff break; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.