搞二个晚上,终于可以用java后台代码编写前台界面了,出来后确没有想象的哪么兴奋,仔细一想这不正是历史的倒退吗。学java第一个程序就是用swing写的,全java编程,哈哈,又走回去了,人真贱。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout earth=new LinearLayout(this);
earth.setOrientation(LinearLayout.VERTICAL);//竖排版
LinearLayout.LayoutParams earthRoom=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT
);
LinearLayout topLayout=new LinearLayout(this);
topLayout.setOrientation(LinearLayout.HORIZONTAL);//横排版
LinearLayout.LayoutParams topRoom=new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
Button buttonSw= new Button(this);
//buttonYs.setId("@+id/Button_colo_sw");
buttonSw.setText(R.string.bottom_colo_sw);
Button buttonYs= new Button(this);
//buttonYs.setId("@+id/Button_colo_sw");
buttonYs.setText(R.string.bottom_colo_ys);
topLayout.addView(buttonSw);
topLayout.addView(buttonYs);
earth.addView(topLayout,topRoom);
LinearLayout midImage=new LinearLayout(this);
midImage.setOrientation(LinearLayout.HORIZONTAL);//横排版
LinearLayout.LayoutParams midImageRoom = new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
ImageView imView11 = new ImageView(this);
imView11.setImageResource(0x7f020002);
ImageView imView12 = new ImageView(this);
imView12.setImageResource(R.drawable.icon);
ImageView imView13 = new ImageView(this);
imView13.setImageResource(R.drawable.icon);
midImage.addView(imView11);
midImage.addView(imView12);
midImage.addView(imView13);
earth.addView(midImage,midImageRoom);//加入第一排图票
this.setContentView(earth,earthRoom);
更多研究可以看下面的文章