Android中Window添加View的底层原理

2019-12-10 18:54:25刘景俊

3.更新window
看下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); 
      mParams.remove(index); 
      mParams.add(index, wparams); 
      root.setLayoutParams(wparams, false); 
    } 
  } 

通过viewRootImpl的setLayoutParams更新viewRootImpl的layoutParams,接着scheduleTraversals对view重新布局,包括测量,布局,重绘,此外它还会通过WindowSession来更新window。这个过程由WindowManagerService实现。这跟上面类似,就不再重复,到此Window底层源码就分析完啦。

以上就是本文的全部内容,希望对大家的学习有所帮助。



注:相关教程知识阅读请移步到Android开发频道。