LayoutInflater 的inflate后会调用createView来创建View对象。
createView中传入三个参数name,prefix,attrs。我们以RelativeLayout为例。
当LayoutInflate中的xml解析器解析到RelativeLayout标签后,根据prifix包名。找到对应的类。
反射调用RelativeLayout类的构造函数,且传入两个参数,1 = context,2 = attrs。
然后RelativeLayout最终调用到四个参数的构造函数调:
(context,attrs,defstyleAttr = 0,efstyleAttr = 0)
然后调用super也就是viewGroup,继续调用super也就是View四个参数的构造函数。
View构造函数中。使用:
context.obtainstyledAttributes创建TyppedArray
TyppedArray的getDrawable调用自身getDrawableForDesity调用Resource的loadDrawable调用loadDrawableForCookie,然后找不到资源报错
context.obtainStyledAttributes(传入四个参数 attrs,con.android.internal.R.styleable.View,defStyleAttr = 0,defStyleRes = 0)调用了getTheme.obtainStyledAttributes