Disable default animation from Portrait to Landscape

后端 未结 8 1180
庸人自扰
庸人自扰 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: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)

提交回复
热议问题