Use the following method:
Button myButton = (Button) findViewById(R.id.buttonid);
LayoutParams buttonparam = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT,1.0f);
myButton.setLayoutParams(buttonparam);
LayoutParams(layout_width,layout_height,layout_weight);