0

i have dynamically created lot of buttons.How to add spaces between two buttons. please help me. Thanks in advance

My code:

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);
Nermeen
  • 15,883
  • 5
  • 59
  • 72
AndroidRaji
  • 907
  • 14
  • 26
  • Add margins ..... http://stackoverflow.com/questions/4472429/change-the-right-margin-of-a-view-programmatically – Santhosh Oct 23 '12 at 07:07

3 Answers3

5

Use LayoutParams Study here for LinearLayout

You can Use RelativeLayout Params also See here

Then you can use setMargins(). Last set These values to your dynamically created button. I am not posting any code. Code example has been given in Nunu's post.

Happy coding :)

Abhi
  • 8,935
  • 7
  • 37
  • 60
1
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(10, 0, 0, 0);
params.setLayoutParams(urButton);
Santhosh
  • 4,956
  • 12
  • 62
  • 90
0

You can add margins..for example..

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);
Nermeen
  • 15,883
  • 5
  • 59
  • 72