// 生成一个LinearLayout,作为布局容器来动态添加3个Button
final LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
setContentView(layout);
// 生成3个Button
final Button btn1 = new Button(this);
btn1.setText("1");
btn1.setText("Button1");
final Button btn2 = new Button(this);
btn2.setText("2");
btn2.setText("Button2");
final Button btn3 = new Button(this);
btn3.setText("3");
btn3.setText("Button3");