一,写在前面
在阅读本篇文章前,建议先了解使用WindowManager添加窗口的内部实现原理,可以参考文章
Android 源码解析之WindowManager添加窗口。本篇文章将从源码角度解析WindowManager更新窗口,也算是WindowManager添加,删除,更新窗口的完结篇。由于跟添加窗口比较类似,只会简单介绍下代码流程,不再重复介绍一些类,接口等。
二,WindowManager更新窗口
前面已经讲过,更新窗口实际上是调用WindowManagerImpl$updateViewLayout方法。
查看WindowManagerImpl$updateViewLayout源码如下:
@Override
public void updateViewLayout(@NonNull View view, @NonNull ViewGroup.LayoutParams params) {
applyDefaultToken(params);
mGlobal.updateViewLayout(view, params);
}
继续查看WindowManagerGlobal$updateViewLayout源码:
public void updateViewLayout(View view, ViewGroup.LayoutParams params) {
if (view == null) {
throw new IllegalArgumentException("view must not be null");
}
if (!(params instanceof WindowManager.LayoutParams)) {
throw new IllegalArgumentException("Params must be WindowManager.LayoutParams");
}
final WindowManager.LayoutParams wparams = (WindowManager.LayoutParams)params;
view.setLayoutParams(wparams);
synchronized (mLock) {
int index = findViewLocked(view, true);
ViewRootImpl root = mRoots.get(index);