2011-06-27 46 views
0

是否可以在我們自己創建的視圖內設置buttonimagebutton,並設置按鈕或圖像按鈕的位置。如何在由我們自己創建的視圖中設置按鈕或圖像按鈕以及它的位置

public class TestingGraphics extends Activity { 
    /** Called when the activity is first created. */ 
    RelativeLayout layout; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     layout = new RelativeLayout(this); 
     layout.setId(R.layout.main); 
     setContentView(layout); 
     Button button = new Button(this); 
     /*----------------------------------*/ 
    } 
+0

請顯示您創建的視圖的代碼 – Egor

回答

0

這已經討論過很多。我相信你正在尋找的短語是「動態添加按鈕」。一旦你瞭解了它的全部基礎知識,它就非常簡單,你應該能夠動態地(在你的程序中)設置按鈕的任何屬性,無論它是大小,位置,還是onClickListener()。查看here的基本示例。希望能幫助到你。