title: center button programmatically and dynamic layout
body: <p>I try to set the button in the center of layout but not work, I need to center the item not the text. The code is:</p>
  
  <pre><code>ScrollView sv = new ScrollView(this);
  sv.setBackgroundColor(Color.parseColor("#E7E7E7"));
  linearLayout = new LinearLayout(this);
  linearLayout.setOrientation(LinearLayout.VERTICAL);
  linearLayout.setBackgroundColor(Color.parseColor("#E7E7E7"));
  sv.addView(linearLayout);
  for (int i = 0; i &lt; jsonHeader.length(); i++) { setting textview and edittext to the layout}
  
  Button datos_OK = new Button(DataObjectActivity.this);
      datos_OK.setText("Aceptar");
      RelativeLayout.LayoutParams testLP = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      testLP.addRule(RelativeLayout.CENTER_IN_PARENT);
  
      datos_OK.setLayoutParams(testLP);
      datos_OK.setBackgroundResource(R.drawable.button_drawable_init);
      datos_OK.setTextColor(Color.WHITE);
      linearLayout.addView(datos_OK);
  </code></pre>
  
  <p>That code not works on my phone and i don't know why. Another question, how can I set colour to my code? Thanx a lot.</p>