标签:cti on c r as text rom class view
LayoutInflater的作用是导入界面,说白了就是查找layout中的.xml界面并导入。如下:
public class MainActitivity extends Acticity{
TextView textView;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
textView=(TextView)findViewById(R.id.textView);
LayoutInflater layoutInflater=LayoutInflater.from(this);
View view=layoutInflater.inflate(R.layout.activity_main,null);
setContentView(view);
}
}
以上类中,setContentView(R.layout.activity_main)是可以被
LayoutInflater layoutInflater=LayoutInflater.from(this);
View view=layoutInflater.inflate(R.layout.activity_main,null);
setContentView(view);
代替的,但其作用不仅如此,如果想要到导入新的界面,完全可用LayoutInflater
标签:cti on c r as text rom class view
原文地址:http://www.cnblogs.com/zhongshujunqia/p/3973626.html