以下 LayoutInflater 有什么区别,这是最有效的方法。
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.buttons,null);
View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.buttons,null);
View view = getLayoutInflater().inflate(R.layout.buttons, mainLayout,false);