Android: Dynamically Set LinearLayout Width, Height, and Weight

2/28/2014 7:07:23 PM

The following will update the layout width, height, and weight of a layout placed in an XML file for an activity.

float layoutWeight = 1;

LinearLayout layoutStuff = (LinearLayout) findViewById(R.id.main_myLinearLayout);

LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, layoutWeight);
layoutStuff.setLayoutParams(layoutParams);