Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: change LayoutParams of View added by WindowManager

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?

like image 452
Dmitry Frank Avatar asked Feb 20 '12 08:02

Dmitry Frank


2 Answers

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

windowManager.updateViewLayout(my_view, my_view_layout_params);
like image 138
Reuben Scratton Avatar answered Nov 04 '22 19:11

Reuben Scratton


You can use this:

wm.updateViewLayout(my_view,my_view_layout_params);
like image 23
Leo Kong Avatar answered Nov 04 '22 21:11

Leo Kong