android後臺佈局

搞二個晚上,終於可以用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);

更多研究可以看下面的文章

http://www.eoeandroid.com/archiver/tid-15263.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章