Android:更改WindowManager添加的View的LayoutParams
我有由 WindowManager
管理的覆盖 View
,就像这个问题。
简而言之,它看起来像这样:
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);
它可以工作,但是如果我需要更改布局参数,我需要删除 View 并再次添加它,就像这样:
wm.removeView(my_view);
wm.addView(my_view, my_view_layout_params);
它看起来不是很漂亮。我尝试执行 my_view.setLayoutParams(my_view_layout_params)
,但不幸的是它不起作用。我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以使用这个:
You can use this:
WindowManager 有一个
updateViewLayout()
成员...这肯定正是您想要的吗?WindowManager has an
updateViewLayout()
member... surely that's exactly what you want?