It should be something like:
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, WEIGTH_HERE);
Assuming WEIGHT_HERE is a float (a throw may be required).
(I don't know if this is a good way to do this, but it should do what you want)
And if you want to use this with a button or something, just do the same without the WEIGHT options and add:
Button b = new Button(this); param.weight= (float) 0.5
But this method will create a new Layout Paramater parameter, so if you want everything to do the same, but do not create a new layout, edit the existing one to get it:
LinearLayout.LayoutParams mLay = (LinearLayout.LayoutParams)myLay.getLayoutParams(); mLay.weight = (float) WEIGTH
Nico
source share