Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2019-10-30:关于LayoutInflater,它是如何通过 inflate 方法获取到具体View的? #177

Open
Moosphan opened this issue Oct 30, 2019 · 4 comments

Comments

@Moosphan
Copy link
Owner

Ps:请从源码角度分析相关方法。

@MrShuHong
Copy link

系统通过LayoutInflater.from创建出布局构造器,inflate方法中,最后会掉用createViewFromTag 这里他会去判断 两个参数 factory2 和factory 如果都会空就会系统自己去创建view, 并且通过一个xml解析器,获取标签名字,然后判断是<Button还是xxx.xxx.xxView. 然后走createView 通过拼接得到全类名路径,反射创建出类。

@icytz
Copy link

icytz commented Nov 27, 2019

layoutInflater.inflate 会根据root标签判断是否是merge 是merge则解析merge标签,否则createViewFromTag创建view,优先factory2 没有就factory 来createview 优先 new 如果为空则拼接字符串来反射创建view

@mlinqirong
Copy link

通过XML pull解析方式获取view标签 通过反射创建view标签的view对象

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants