我尝试了kagronick的答案,但无法正常工作。经过一番混乱之后,我最终使用系统覆盖窗口使其工作并删除了我发现不必要的LayoutParam。这是我最终的解决方案:orientationChanger = new LinearLayout(this);// Using TYPE_SYSTEM_OVERLAY is crucial to make your window appear on top// You'll need the permission android.permission.SYSTEM_ALERT_WINDOWWindowManager.LayoutParams orientationLayout = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 0, PixelFormat.RGBA_8888);// Use whatever constant you need for your desired rotationorientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;WindowManager wm = (WindowManager) this.getSystemService(Service.WINDOW_SERVICE);wm.addView(orientationChanger, orientationLayout);orientationChanger.setVisibility(View.VISIBLE);您可以在基于此发布的应用程序中看到我的成功:强制停靠旋转。