layoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
............
ActivityInfo aInfo = r.activityInfo;
}
activity.attach(appContext, this, getInstrumentation(), r.token,
r.ident, app, r.intent, r.activityInfo, title, r.parent,
r.embeddedID, r.lastNonConfigurationInstances, config,
r.referrer, r.voiceInteractor);
//创建PhoneWindow,用于视图加载
mWindow = new PhoneWindow(this);
//将window事件通过回调接口,传递到Activity来处理
mWindow.setCallback(this);
mWindow.setOnWindowDismissedCallback(this);
mWindow.getLayoutInflater().setPrivateFactory(this);
//设置WindowManger
mWindow.setWindowManager(
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
mToken, mComponent.flattenToString(),
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
public void setContentView(int layoutResID) {
if (mContentParent == null) {
installDecor();
} else if (!hasFeature(FEATURE_CONTENT_TRANSITIONS)) {
mContentParent.removeAllViews();
}
................
}
}
installDecor方法最终创建DecorView
private void installDecor() {
mForceDecorInstall = false;
if (mDecor == null) {
// 这里创建了DecorView
mDecor = generateDecor(-1);
...
} else {
mDecor.setWindow(this);
}
if (mContentParent == null) {
// 对DecorView进行初始化,得到ContentView
mContentParent = generateLayout(mDecor);
...
}
}
void makeVisible() {
if (!mWindowAdded) {
//将DecorView添加到WindowManager
ViewManager wm = getWindowManager();
wm.addView(mDecor, getWindow().getAttributes());
mWindowAdded = true;
}
mDecor.setVisibility(View.VISIBLE);
}
public void addView(View view, ViewGroup.LayoutParams params,
Display display, Window parentWindow) {
//ViewRootImpl 创建
root = new ViewRootImpl(view.getContext(), display);
.........
root.setView()
}
public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
synchronized (this) {
.........
requestLayout();
.................
//通过IPC,添加window交给WindowMangerServer
res = mWindowSession.addToDisplay(mWindow, mSeq, mWindowAttributes,
getHostVisibility(), mDisplay.getDisplayId(),
mAttachInfo.mContentInsets, mAttachInfo.mStableInsets,
mAttachInfo.mOutsets, mInputChannel);
.........
}
}
Window和View是什么关系
在测量Layout绘制之前需要有哪些准备工作
View树什么时候建立好的
addView什么时候能获取宽高
DecorView什么时候创建的
View什么时候能获取准确宽高
参考:
https://juejin.cn/post/6888688477714841608
https://www.jianshu.com/p/96c9ca5431c7