使用inflater实现窗体布局
/* 传统的方式 */ // setContentView(R.layout.main); /* inflater方式 */ LayoutInflater inflater = LayoutInflater.from(Inflate.this);// 生成inflater对象 LinearLayout mainFrame = (LinearLayout) inflater.inflate(R.layout.main,null);// 找到窗体的布局文件 LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); this.addContentView(mainFrame, params);
?
LayoutInflaterinflater=LayoutInflater.from(this); LayoutInflaterinflater=getLayoutInflater(); LayoutInflaterinflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
?