Android:更改 WindowManager 添加的 View 的 LayoutParams [英] Android: change LayoutParams of View added by WindowManager

查看:84
本文介绍了Android:更改 WindowManager 添加的 View 的 LayoutParams的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有由 WindowManager 管理的叠加 View,就像在 this问题.

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);

它有效,但如果我需要更改布局参数,我需要删除 View 并再次添加它,如下所示:

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);

看起来不是很漂亮.我试图做 my_view.setLayoutParams(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?

推荐答案

WindowManager 有一个 updateViewLayout() 成员...确定这正是您想要的吗?

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

windowManager.updateViewLayout(my_view, my_view_layout_params);

这篇关于Android:更改 WindowManager 添加的 View 的 LayoutParams的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆