Android中LayoutInflater的使用

Posted by PanMin on April 22, 2015

Android中LayoutInflater的使用

第一种方法:

LayoutInflater inflater = LayoutInflater.from(this);  
View layout = inflater.inflate(R.layout.main, null);  

第二种方法:

LayoutInflater inflater = getLayoutInflater();  
View layout = inflater.inflate(R.layout.main, null); 

第三种方法:

LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);  
View layout = inflater.inflate(R.layout.main, null);