Quiero que mi aplicación Android solo se ejecute en modo retrato?


¿Quiero que mi aplicación Android solo se ejecute en modo retrato? ¿Cómo puedo hacer eso?

Author: Ronak Thakkar, 2010-09-16

6 answers

En el manifiesto, pon esto para todas tus actividades:

<activity android:name=".YourActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"/>

Permítanme explicar:

  • Con android:configChanges="orientation" le dices a Android que serás responsable de los cambios de orientación.
  • android:screenOrientation="portrait" se establece el modo de orientación predeterminado.
 636
Author: Cristian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-16 04:54:41

En el archivo de manifiesto de Android, poner atributo para su <activity> que android:screenOrientation="portrait"

 43
Author: Praveen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-09-16 04:55:50

Hay dos maneras,

  1. Agregar android:screenOrientation="portrait" para cada Actividad en el Archivo de Manifiesto
  2. Agregue this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); en cada archivo java.
 23
Author: Android Code Solution,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-18 11:49:15

Viejo post que conozco. Para ejecutar su aplicación siempre en modo vertical, incluso cuando la orientación puede ser o se intercambia, etc. (por ejemplo, en tabletas) Diseñé esta función que se utiliza para configurar el dispositivo en la orientación correcta sin la necesidad de saber cómo se organizan las características de retrato y paisaje en el dispositivo.

   private void initActivityScreenOrientPortrait()
    {
        // Avoid screen rotations (use the manifests android:screenOrientation setting)
        // Set this to nosensor or potrait

        // Set window fullscreen
        this.activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        DisplayMetrics metrics = new DisplayMetrics();
        this.activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

         // Test if it is VISUAL in portrait mode by simply checking it's size
        boolean bIsVisualPortrait = ( metrics.heightPixels >= metrics.widthPixels ); 

        if( !bIsVisualPortrait )
        { 
            // Swap the orientation to match the VISUAL portrait mode
            if( this.activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT )
             { this.activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }
            else { this.activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ); }
        }
        else { this.activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR); }

    }

Funciona como un encanto!

AVISO: Cambie this.activity por su actividad o agréguela a la actividad principal y elimínela this.activity ;-)

 3
Author: Codebeat,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-13 10:33:26

Utilizo

 android:screenOrientation="nosensor"

Es útil si no desea admitir el modo vertical hacia arriba y hacia abajo.

 -4
Author: user2305886,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-22 05:45:24

En el manifiesto, establece esto para todas tus actividades:

<activity android:name=".YourActivity"
  android:configChanges="orientation"
  android:screenOrientation="portrait"/>
 -8
Author: Android Code Solution,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-10 00:15:29