转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/125377224
本文出自【赵彦军的博客】
覆写 onFinishInflate
/**
* @Description:
* @author: zhaoyj
* @date: 2022/6/20
*/
public class MyView extends View {
public MyView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
}
}
View
的 onFinishInflate
是一个空方法。
即使子类覆写了 onFinishInflate 也应该调用 super.onFinishInflate()
onFinishInflate 什么时候会被回调
我们知道 Activity
的 setContentView
方法,最终会调用 PhoneWindow
的 setContentView
。
PhoneWindow
的 setContentView
方法,会使用 LayoutInflater
解析布局,并且把布局添加到 R.id.content
中,可以理解为添加到 DecorView
中
在完成把 子view
添加到 ViewGroup
中,会调用 parent.onFinishInflate()
函数调用顺序
构造函数
onFinishInflate
onMeasure
onLayout
onDraw