just set layout params in that layout like
create param variable
android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
1f is weight variable
set your widget or layout like
TextView text = (TextView) findViewById(R.id.text);
text.setLayoutParams(params);