Android: change LayoutParams of View added by WindowManager

…衆ロ難τιáo~ 提交于 2019-12-09 14:42:33

问题


I have overlay View managed by WindowManager, just like in this question.

Briefly, it looks like this:

WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
my_view_layout_params = new WindowManager.LayoutParams(
       WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
       WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
       PixelFormat.TRANSLUCENT);

wm.addView(my_view, my_view_layout_params);

It works, but if i need to change layout params, i need to remove View and add it again, like that:

wm.removeView(my_view);
wm.addView(my_view, my_view_layout_params);

It looks not very beautiful. I tried to do my_view.setLayoutParams(my_view_layout_params), but it does not work unfortunately. How can i do it?


回答1:


WindowManager has an updateViewLayout() member... surely that's exactly what you want?

windowManager.updateViewLayout(my_view, my_view_layout_params);



回答2:


You can use this:

wm.updateViewLayout(my_view,my_view_layout_params);


来源:https://stackoverflow.com/questions/9358288/android-change-layoutparams-of-view-added-by-windowmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!