LayoutInflater源码分析
- 与setContentView相关
在PhoneWindow的generateLayout中调用了
1
View in = mLayoutInflater.inflate(layoutResource, null);
LayoutInflater中获取实例化方法
1
2
3
4
5
6
7
8
9
10
11/**
* Obtains the LayoutInflater from the given context.
*/
public static LayoutInflater from(Context context) {
LayoutInflater LayoutInflater =
(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (LayoutInflater == null) {
throw new AssertionError("LayoutInflater not found.");
}
return LayoutInflater;
}inflate方法相关
1
2
3
4
5
6
7public View inflate(int resource, ViewGroup root) {
return inflate(resource, root, root != null);
}
public View inflate(XmlPullParser parser, { ViewGroup root)
return inflate(parser, root, root != null);
}1
2
3
4
5
6
7
8
9
10
11
12
13
14public View inflate(int resource, ViewGroup root, boolean attachToRoot) {
final Resources res = getContext().getResources();
if (DEBUG) {
Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("
+ Integer.toHexString(resource) + ")");
}
final XmlResourceParser parser = res.getLayout(resource);
try {
return inflate(parser, root, attachToRoot);
} finally {
parser.close();
}
}最后发现都需要调用
1 | public View inflate(XmlPullParser parser, boolean attachToRoot) { ViewGroup root, |
相关inflate参数的结果
- 相关方法解析
在Inflate中多次被调用的rInflate
1 | void rInflate(XmlPullParser parser, View parent, Context context, |