查看源码:
public View inflate(int resource, ViewGroup root) {
return inflate(resource, root, root != null);
}
也就是说
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflate(R.layout.item_lv_test, null);
}
return convertView;
}
如果用上面的代码会发现设置100dp是无效的。而如果换成下面的代码就可以了。
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = inflate(R.layout.item_lv_test, parent, false);
}
return convertView;
}
参考:http://blog.csdn.net/guolin_blog/article/details/12921889
https://github.com/CharonChui/AndroidNote/blob/master/Android%E5%AD%A6%E4%B9%A0%E5%8A%A0%E5%BC%BA/LayoutInflater.inflate%E8%AF%A6%E8%A7%A3.md