2012-10-23 88 views
0

動態創建的按鈕之間添加空間我已經動態地創建了很多按鈕。如何在兩個按鈕之間添加空格。請幫幫我。在此先感謝如何在Android

我的代碼:

private LinearLayout LLDynamic; 

private RelativeLayout.LayoutParams ParaOne; 

ParaOne = new RelativeLayout.LayoutParams(280, 30); 

Button button1= new Button(Twindo_fromEditGroup.this); 
button1.setTextSize(16); 


LLDynamic = new LinearLayout(Twindo_fromEditGroup.this); 
LLDynamic.setOrientation(LinearLayout.VERTICAL); 
LLDynamic.addView(button1,ParaOne); 
+0

添加利潤率..... http://stackoverflow.com/questions/4472429/change-the-right-margin-of-a-view-programmatically – Santhosh

回答

0

您可以添加margins..for例子..

Button button1 = new Button(this); 
LinearLayout.LayoutParams rel_button1 = new LinearLayout.LayoutParams(buttonWidth, buttonHeight); 
rel_button1.setMargins(20, 0, 0, 0); 
button1.setLayoutParams(rel_button1); 
0
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
params.setMargins(10, 0, 0, 0); 
params.setLayoutParams(urButton); 
5

使用的LayoutParams Study here for LinearLayout

可以使用的RelativeLayout Params也See here

然後你可以使用setMargins()。最後將這些值設置爲您的動態創建的按鈕。我沒有發佈任何代碼。代碼示例已在Nunu的帖子中給出。

編碼愉快:)