title: Adding margins to button object programatically
body: <p>Need to set left margin to a button object programatically.
  This is the code segment:</p>
  
  <pre><code>RelativeLayout rl = (RelativeLayout) findViewById(R.id.for_button);
  MarginLayoutParams ml = new MarginLayoutParams(-2,-2);
  ml.setMargins(5, 0, 0, 0);
  
  Button btn = new Button(this);
  btn.setText("7");
  btn.setTextColor(Color.WHITE);
  btn.setBackgroundResource(R.drawable.date_button);
  
  rl.addView(btn,ml)
  </code></pre>
  
  <p>I also tried </p>
  
  <pre><code>btn.setLayoutParams(ml);
  rl.addView(btn);
  </code></pre>
  
  <p>Whats the big problem. Or is there any alternative way?</p>