不能删除由windowManager.addView连接视图() [英] Cannot remove a view attached by windowManager.addView()
本文介绍了不能删除由windowManager.addView连接视图()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图删除添加到窗口管理层。但是,当我打电话removeView()什么也不会发生。
有谁知道如何去除呢?我的code看起来是这样的。
公共类MainActivity扩展活动实现View.OnClickListener { 私人窗口管理WM;
私人WindowManager.LayoutParams orientationLayout;
私人的LinearLayout orientationChanger; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); //初始化景观事情
WM =(窗口管理器)getApplicationContext()getSystemService(Service.WINDOW_SERVICE)。
orientationChanger =新的LinearLayout(getApplicationContext());
orientationChanger.setClickable(假);
orientationChanger.setFocusable(假);
orientationChanger.setFocusableInTouchMode(假);
orientationChanger.setLongClickable(假);
orientationLayout =新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视图
的setContentView(R.layout.calibrate); findViewById(android.R.id.button).setOnClickListener(本); lockLandScape();
} 公共无效lockLandScape(){
wm.addView(orientationChanger,orientationLayout); orientationChanger.setVisibility(View.GONE);
orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
wm.updateViewLayout(orientationChanger,orientationLayout);
orientationChanger.setVisibility(View.VISIBLE);
} 公共无效releaseLandScape(){
wm.removeView(orientationChanger); //这不工作,以及
//wm.removeViewImmediate(orientationChanger);
} @Overrride
公共无效的onClick(查看视图){
Log.i(MyApp的,点击)
releaseLandScape();
}}
解决方案
而不是使用像WM的属性,你可以尝试使用
(窗口管理器)getApplicationContext()。getSystemService(Service.WINDOW_SERVICE)
每次?
这样的:
((窗口管理器)getApplicationContext()getSystemService(Service.WINDOW_SERVICE)。)removeView(orientationChanger)。
I'm trying to remove a layer added to WindowManager. But nothing happens when I call removeView(). Does anybody know how to remove it? My code looks like this.
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();
}
}
解决方案
Instead of using an attribute like wm, could you try using
(WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)
everytime ?
like :
((WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE)).removeView(orientationChanger);
这篇关于不能删除由windowManager.addView连接视图()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文