0

我通过 addView() 添加视图,并且我想将该视图上的屏幕方向阻止为纵向。我试过了:

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.FILL_PARENT,
            WindowManager.LayoutParams.FILL_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                    | WindowManager.LayoutParams.FLAG_FULLSCREEN,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.CENTER | Gravity.TOP;
    params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;

    LinearLayout glass = new LinearLayout(this);
    glass.setBackgroundResource(R.drawable.glass6);

    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(glass, params);

它不起作用。我该怎么做?另外,我怎样才能使我的新视图在应用程序关闭后不会消失?

4

2 回答 2

1

尝试这个

glass.setOrintation(Configuration.ORIENTATION_LANDSCAPE)
于 2012-08-17T12:06:08.200 回答
-1

在您的清单文件中使用android:screenOrientation="landscape"or android:screenOrientation="portrait"。限制您的活动在portraitorlandscape模式下查看。

于 2012-08-17T11:55:07.143 回答