Disable default animation from Portrait to Landscape

后端 未结 8 1069
庸人自扰
庸人自扰 2020-11-27 03:30

I have an app with several \'normal\' activities which can run on either landscape or portrait. They are designed for and mostly used on portrait.

This app has one s

相关标签:
8条回答
  • 2020-11-27 04:04

    Sorry there is no way to control the rotation animation. This is done way outside of your app, deep in the window manager where it takes a screenshot of the current screen, resizes and rebuilds the UI behind it, and then runs a built-in animation to transition from the original screenshot to the new rebuilt UI. There is no way to modify this behavior when the screen rotation changes.

    0 讨论(0)
  • 2020-11-27 04:05

    If you want to set your activities in portrait mode only you can do it in your manifest file like this

     <activity
         android:name=".Qosko4Activity"
         android:label="@string/app_name"
         android:screenOrientation="portrait" >
         <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
     </activity>
    
    0 讨论(0)
  • 2020-11-27 04:08

    Against them who said no I say yes it is possible and it is very simple! The first thing may sound stupid but lock your application to the desired orientation! Then keep asking the gyrometer what orientation the device has an last but not least rotate or animate your views to the new orientation!

    Edit: you may want to hide the system ui since it won't rotate. Mario

    0 讨论(0)
  • 2020-11-27 04:12

    This is the way how the stock camera app disables rotation animation:

    private void setRotationAnimation() {
        int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        winParams.rotationAnimation = rotationAnimation;
        win.setAttributes(winParams);
    }
    

    Note: According to API Reference and comment below, this only works:

    • On API level 18 or above
    • The FLAG_FULLSCREEN flag is set for WindowManager.LayoutParams of the Activity
    • The Activity is not covered by another window (e.g. the Power Off popup triggered by long pressing the Power button)
    0 讨论(0)
  • 2020-11-27 04:14

    I've put that in the mainActivity and it cancelled the rotation animation:

    @Override
        public void setRequestedOrientation(int requestedOrientation) {
            super.setRequestedOrientation(requestedOrientation);
    
            int rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
            Window win = getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            winParams.rotationAnimation = rotationAnimation;
            win.setAttributes(winParams);
    
        }
    

    More details here.

    0 讨论(0)
  • 2020-11-27 04:15

    You can set in the AndroidManifest a property called android:configChanges where you can decide which changes you want to manage in code. In this way, the rotation change animation will be disabled and you can handle it as you want in the method onConfigurationChanged of your Activity.

    This should work, but according to this page you should also add screenSize to configChanges by adding android:configChanges="orientation|screenSize" to your Activity Tag.

    0 讨论(0)
提交回复
热议问题