2014-04-08 145 views
0

即时通讯尝试使用GUI来执行Android应用程序,以使用apwidgets库控制arduino。Android添加按钮

现在我有4个按钮并排..但我想在每个按钮下添加更多的按钮(我的意思是我想添加按钮的红色按钮等,但idont知道这种语言。帮帮我吗?

//Setup GUI******************************** 
buttonWidth=((width/n)-(n*gap)); 
buttonHeight=(height/2); 
widgetContainer = new APWidgetContainer(this); //create new container for widgets 
redButton =new APButton((buttonWidth*(n-4)+(gap*1)), gap, buttonWidth, buttonHeight, "RED"); //Create a RED button 
greenButton = new APButton((buttonWidth*(n-3)+(gap*2)), gap, buttonWidth, buttonHeight, "GREEN"); //Create a GREEN button 
blueButton = new APButton((buttonWidth*(n-2)+(gap*3)), gap, buttonWidth, buttonHeight, "BLUE"); //Create a BLUE button 
offButton = new APButton((buttonWidth*(n-1)+(gap*4)), gap, buttonWidth, buttonHeight, "OFF"); //Create a OFF button 
widgetContainer.addWidget(redButton); //place red button in container 
widgetContainer.addWidget(greenButton); //place green button in container 
widgetContainer.addWidget(blueButton);//place blue button in container 
widgetContainer.addWidget(offButton);//place off button in container 
background(0); //Start with a black background 
+2

我强烈建议您使用XML来声明所有布局(查看内容)。 [声明布局](http://developer.android.com/guide/topics/ui/declaring-layout.html) – FMontano

+0

谢谢你的回复,但我使用处理ide,我做按钮使用apwidgets库。你认为,XML适用于处理android ide。 ? – Burak

+0

我从来没有用过它:/对不起,我不能有任何帮助。 – FMontano

回答

0

就是这么简单,我只是增加了一个按钮,呼叫yeniButton。开始的代码APButton redButton, greenButton, blueButton, offButton,yeniButton;
AN重要的是新的APbutton(INT X,INT Y,按钮宽度,按钮的高度,”名称“); 和我定义了一个新的按钮,你可以看到下面的代码

buttonWidth=((width/n)-(n*gap)); 
    buttonHeight=(height/2); 
    widgetContainer = new APWidgetContainer(this); //create new container for widgets 
    yeniButton = new APButton(700,600,(buttonWidth/2),(buttonHeight/2),"Yeni buton"); 
    redButton =new APButton((buttonWidth*(n-4)+(gap*1)), gap, buttonWidth, buttonHeight, "RED"); //Create a RED button 
    greenButton = new APButton((buttonWidth*(n-3)+(gap*2)), gap, buttonWidth, buttonHeight, "GREEN"); //Create a GREEN button 
    blueButton = new APButton((buttonWidth*(n-2)+(gap*3)), gap, buttonWidth, buttonHeight, "BLUE"); //Create a BLUE button 
    offButton = new APButton((buttonWidth*(n-1)+(gap*4)), gap, buttonWidth, buttonHeight, "OFF"); //Create a OFF button 
    widgetContainer.addWidget(redButton); //place red button in container 
    widgetContainer.addWidget(greenButton); //place green button in container 
    widgetContainer.addWidget(blueButton);//place blue button in container 
    widgetContainer.addWidget(offButton);//place off button in container 
    widgetContainer.addWidget(yeniButton); 
    background(0); //Start with a black background