有个现有的程序,想在页面里加一个进度条(ProgressBar),不知道不用findViewById()怎么加到页面中????(因为原程序layout里面没有xml文件,程序里面都是通过canvas()加东西)

解决方案 »

  1.   

    找到上一级view,然后创建Progressbar,然后调用一级view的AddChild,将Progressbar添加到上一级view中。
      

  2.   

             // 设置画面布局  
             ll = new LinearLayout(this.getBaseContext());  
             ll.setOrientation(LinearLayout.VERTICAL);  
       
             // button  
             mBtn = new Button(this.getBaseContext());  
             mBtn.setText("Draw");  
             //   
             mBtn.setTextColor(0xff000000);  
             mBtn.setTextSize(16);  
             LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(  
             LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);  
       
             lp.topMargin = 5;  
             lp.leftMargin = 5;  
             ll.addView(mBtn, lp); 
    参考button
    http://blog.csdn.net/ameyume/archive/2010/12/13/6074359.aspx