Domanda

I am developing application that is somehow similar to camera, I wish that the app will always be in landscape mode witch I achieve with:

android:screenOrientation="portrait"

But I need to know when user rotates the phone to landscape mode so I can rotate the icons 90 degrees.

I have tried:

   if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 
    {
        Toast.makeText(getApplicationContext(), "ORIENTATION_LANDSCAPE", Toast.LENGTH_SHORT).show();

    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){

        Toast.makeText(getApplicationContext(), "ORIENTATION_PORTRAIT", Toast.LENGTH_SHORT).show();
    }

But it only works when I add:

android:configChanges="keyboardHidden|orientation|screenSize"

And its also change my orientation automatically.

So how can I keep my app always in Landscape mode and only detect when the phone is in Portrait without that phone automatically change anything? Just like in camera app

È stato utile?

Soluzione

Using android:configChanges="keyboardHidden|orientation|screenSize" is a good idea.

Now try setting your orientation manually:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Altri suggerimenti

This will help. It did for me and I needed to do exactly what you needed to do.

https://stackoverflow.com/a/5183690/687245

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top