I have a Linear Layout inside a Relative Layout in the LinearLayout i have Two image buttons which have weight 50 each, i want to set the weight of one ImageButton to 100 using java
Asked
Active
Viewed 560 times
-2
-
2Possible duplicate of [How to set layout\_weight attribute dynamically from code?](http://stackoverflow.com/questions/4641072/how-to-set-layout-weight-attribute-dynamically-from-code) – rafsanahmad007 Feb 21 '17 at 15:14
2 Answers
1
Try this to set weight
dynamically
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) imagebutton.getLayoutParams();
layoutParams.weight = 1.0f;
imagebutton.setLayoutParams(layoutParams);
Refer this for more details How to set layout_weight attribute dynamically from code?
1
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.weight = 1;
imagebutton.setLayoutParams(p);

Buh Buh
- 7,443
- 1
- 34
- 61

Zakir hussain
- 392
- 1
- 10