public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FrameLayout layout= new FrameLayout(this);//定义框架布局器
FrameLayout.LayoutParams params=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT);//定义框架布局器参数
FrameLayout.LayoutParams tparams=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);//定义显示组件参数
TextView txtview = new TextView(this);//定义组件
txtview.setText("欢迎使用框架布局");
EditText et = new EditText(this);
et.setText("请选择你喜欢的布局");
Button but=new Button(this);
but.setText("按我");
layout.addView(txtview, tparams);//添加组件
layout.addView(et, tparams);
layout.addView(but, tparams);
setContentView(layout,params);//向屏幕上添加布局显示器
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}