美文网首页Android知识
LayoutInflater方法inflate使用总结

LayoutInflater方法inflate使用总结

作者: 暮雨沉沦 | 来源:发表于2016-11-28 20:23 被阅读86次

本文总结来自鸿洋大神博客 http://blog.csdn.net/lmj623565791/article/details/38171465

inflate常用的方法有两个:

1、inflate(layoutId, null )

2、inflate(layoutId, root, false )  参数:布局id, 副布局view,  是否添加到该布局

有四种调用情况(第二个接口的root为空时跟第一个接口一致)

a、inflate(layoutId, null )  

b、inflate(layoutId, root )

c、inflate(layoutId, root, false )

d、inflate(layoutId, root, true )

经代码验证后结果如下:

a、不能正确地处理layoutId宽和高, 因为:layout_width,layout_height是相对了父级设置的,而root为null

b、当root不为Null时,情况b等同于情况d

c、可以正确处理layoutId宽和高,因为temp.setLayoutParams(params);这个params正是root.generateLayoutParams(attrs);得到的。

d、不仅能够正确的处理,而且已经把layoutId这个view加入到了parent,并且返回的是parent即root

相关文章

网友评论

    本文标题:LayoutInflater方法inflate使用总结

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