You can achieve that by declaring a LinearLayout.LayoutParams
object
tv.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
The third parameter (1f
) is the weight of the layout (in this case 1 (f
stands for float
)).