1

我刚刚安装了应用程序 Rotation Locker。这是一个简单的应用程序,但它工作得很好。它可以强制所有其他应用程序以横向或纵向模式运行。我正在努力弄清楚它是如何做到这一点的。请问有人可以告诉我吗?

4

2 回答 2

1

Piecing together data from other posts I was able how to work this out for an app I was writing that needs to do exactly this. (Force Dock Rotation if you're interested).

My solution involves creating a window and inserting it at the top of the view hierarchy so that you can get first shout of the orientation before another app tries to set it...

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_WINDOW
WindowManager.LayoutParams orientationLayout = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, 0, PixelFormat.RGBA_8888);
// Use whatever constant you need for your desired rotation
orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;

WindowManager wm = (WindowManager) this.getSystemService(Service.WINDOW_SERVICE);
wm.addView(orientationChanger, orientationLayout);
orientationChanger.setVisibility(View.VISIBLE);

Credit to this answer for the inspiration: How can I globally force screen orientation in Android?

于 2013-02-13T20:46:16.567 回答
0

可能您可以按住“搜索”按钮或其他按钮。

这就是它在 HTC Desire 上的工作方式

于 2012-04-28T16:36:42.787 回答