When setting background color to button in android it Hides White Space between buttons in linear layout?

StackOverflow https://stackoverflow.com/questions/23425677

  •  14-07-2023
  •  | 
  •  

Pergunta

I am facing problem, when setting background color to button it hides white space between button in a Linear Layout(Vertical)
 LinearLayout ll=new LinearLayout(thisContext);
 for(int i=0;i<10;i++)
 {
      Button b=new Button(thisContext);
      b.setText("Button"+i);
      b.setBackgroundColor(Color.GREEN);
      ll.addview(b);

 }
Foi útil?

Solução

// try this way,hope this will help you...

LinearLayout ll=new LinearLayout(thisContext);
for(int i=0;i<10;i++)
{
  Button b=new Button(thisContext);
  LinearLayout.LayoutParams bParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
  bParams.setMargins(5,5,5,5);
  b.setLayoutParams(bParams);
  b.setText("Button"+i);
  b.setBackgroundColor(Color.GREEN);
  ll.addview(b);
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top