2

I try to add buttons to the linear layout programmatically .Buttons are added successfully to the linearlayout but between buttons some space is there. I need to remove the space between the buttons how to do this??

I use the following code,but I didn't able to remove the space between the views:

   LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(0, 0, 0, 0);
    Button okButton = new Button(this);
    okButton.setText("some text");
    ll.addView(okButton, layoutParams);
    LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams1.setMargins(0, 0, 0, 0);
    Button okButton1 = new Button(this);
    okButton1.setText("some text");
    ll.addView(okButton1, layoutParams1);

    setContentView(ll);
Rithi
  • 21
  • 1
  • 4
  • The spacing between buttons is built-in, you can give your layout backgroun. – Adil Soomro Dec 29 '11 at 13:45
  • Use layoutParams1.setMargins(-3, -3, -3, -3); Refer [HERE][1] [1]: http://stackoverflow.com/questions/4361309/remove-space-between-buttons – Finder Dec 29 '11 at 14:30

3 Answers3

0

You can try to set layout_margin parameter as you need like here

Community
  • 1
  • 1
Natali
  • 2,934
  • 4
  • 39
  • 53
0

Try using Button.setPadding() when adding the buttons in the layout and set the padding value to zero, if you need to remove padding completely.

Mohamed_AbdAllah
  • 5,311
  • 3
  • 28
  • 47
0

This may help you

int width = LinearLayout.LayoutParams.WRAP_CONTENT;
int height = LinearLayout.LayoutParams.WRAP_CONTENT;

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(width,height);
ll.addView(your_button, layoutParams);
Android Killer
  • 18,174
  • 13
  • 67
  • 90