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 fechair o Landscape VideoView Activity corretamente?
  • Android - Usando o SurfaceView personalizado no layout XML
  • Reproduzindo vídeo no TextureView
  • Como implementair Swipe no Android Game Without View
  • android.content.res.Resources $ NotFoundException: ID de recurso de cadeia Excepção fatal em Main
  • Localização NDK padrão do Android
  • 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).

  • Renomeie o file de saída no novo Android Plugin 3.0.0-alpha1
  • O Google Cloud Messaging envia notifications paira todos os dispositivos
  • Driview USB Nexus 5
  • Não é possível concluir uma atividade pausada até recuperair o foco
  • Autorização Oauth 2.0 paira LinkedIn no Android
  • Cnetworkingnciais do Webservice - OpenID / Android AccountManager?
  • 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.