문제

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

도움이 되었습니까?

해결책

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

Now try setting your orientation manually:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

다른 팁

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top