gpt4 book ai didi

android - 无法删除 windowManager.addView() 附加的 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:46:18 26 4
gpt4 key购买 nike

我正在尝试删除添加到 WindowManager 的图层。但是当我调用 removeView() 时没有任何反应。有人知道如何删除它吗?我的代码如下所示。

public class MainActivity extends Activity implements View.OnClickListener{

private WindowManager wm;
private WindowManager.LayoutParams orientationLayout;
private LinearLayout orientationChanger;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// init landscape things
wm = (WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE);
orientationChanger = new LinearLayout(getApplicationContext());
orientationChanger.setClickable(false);
orientationChanger.setFocusable(false);
orientationChanger.setFocusableInTouchMode(false);
orientationChanger.setLongClickable(false);
orientationLayout = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.RGBA_8888);
orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

// set view
setContentView(R.layout.calibrate);

findViewById(android.R.id.button).setOnClickListener(this);

lockLandScape();
}

public void lockLandScape(){
wm.addView(orientationChanger, orientationLayout);

orientationChanger.setVisibility(View.GONE);
orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
wm.updateViewLayout(orientationChanger, orientationLayout);
orientationChanger.setVisibility(View.VISIBLE);
}

public void releaseLandScape(){
wm.removeView(orientationChanger);

// This doesn't work as well
//wm.removeViewImmediate(orientationChanger);
}

@Overrride
public void onClick(View view){
Log.i("myapp", "clicked")
releaseLandScape();
}

}

最佳答案

除了使用像 wm 这样的属性,你可以尝试使用

(WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)

每次?

喜欢:

((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(orientationChanger);

关于android - 无法删除 windowManager.addView() 附加的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17995014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com