美文网首页
LayoutInflater使用注意

LayoutInflater使用注意

作者: 小鱼你好 | 来源:发表于2022-06-17 15:47 被阅读0次

LayoutInflater作用:

1,利用解析器解析xml
2,利用反射创建View对象

注意点:

创建view的方式:
View view = LayoutInflater.from(context).inflate(resourceId, parent, false);
当不指定parent的时候布局文件中跟布局设置的宽高及margin、padding等都将会失效,会根据子布局进行适配,而不会依据设定大小展示。
如果想使设定生效需要传入非null parent控件。
attachToRoot不设定时默认为true

相关文章

网友评论

      本文标题:LayoutInflater使用注意

      本文链接:https://www.haomeiwen.com/subject/iichvrtx.html