方法一
View.inflate(parent.getContext(),R.layout.dialog_data_item,null);
這個(gè)方法可以得到view,但是對(duì)view中設(shè)置居中等什么屬性都是無效的,還有就是設(shè)置的寬度也是無效的,默認(rèn)只能是wrap
方法二
LayoutInflater.from(context).inflate(R.layout.dialog_data_item,parent,false);
使用這個(gè)方法就能夠正常的給dialog_data_item布局設(shè)置各種屬性顷链,缺點(diǎn)就是需要傳入一個(gè)上下文獲得LayoutInflater夯辖,建議使用這個(gè)笙什,曾經(jīng)被上面的方法坑了一把茵烈,一直得到不自己想要的布局绸吸,查找了半天代碼