加载一个layout的时候,LayoutInflater提供了以下两个方法:
LayoutInflater.inflate(int layoutRes,ViewGroup parent);
LayoutInflater.inflate(int layoutRes,ViewGroup parent,booelan attachToRoot);
以前经常使用第一个方法,且习惯将parent参数填写为null。这种写法造成的问题是LayoutInflater无法读取xml文件最外层容器的属性,比如一些height、width等属性无效。
所以写的时候要记得避免这样做。
参考:
关于LayoutInflater的错误用法 - kobe8 - 博客园 http://www.cnblogs.com/kobe8/p/3859708.html