LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, //OR WRAP_CONTENT -> layout_width
LayoutParams.MATCH_PARENT, //OR WRAP_CONTENT -> layout_height
1.0f // layout_weight 1
);
YOUR_VIEW.setLayoutParams(param);
Android Studio Set Weight Layout Programatically