Blog >Lista Soluciones > Orientación sólo vertical (Portrait)
Y ya está, esta función podemos implementarla también si queremos en alguna ocasión manejar algo en el cambio de orientación :
Más info, en el sitio oficial aquí.
Vamos a configurar nuestra aplicación android para que se ejecute sólo con orientación vertical o portrait.
Esto se hace de una forma muy sencilla, vamos a nuestro AndroidManifiest.xml y añadimos esta línea:
<?xml version="1.0" encoding="utf-8"?><manifest> <application> <activity android:name="mi.paquete.MiActivity" android:screenOrientation="portrait" /> </application></manifest>
Pero oJoOoOo !! También se puede hacer desde la clase java de la actividad, en el onCreate :
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Y ya está, esta función podemos implementarla también si queremos en alguna ocasión manejar algo en el cambio de orientación :
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}
Más info, en el sitio oficial aquí.
|
