9

I have written code to set height and width of view dynamically

view.getLayoutParams().width = 120;
view.getLayoutParams().height = 120;

It works perfectly with below nougat devices, but with nougat it is not working. It is just taking height and width as 0. Any changes after nougat update?

Update :

However it works

1) when i am using view.requestLayout() after setting height and width
2) view.setLayoutParams(new LinearLayout.LayoutParams(200, 120));

So why it is working on pre nougat devices without using these 2 options?

Ravi
  • 34,851
  • 21
  • 122
  • 183

2 Answers2

11

Try to call after setting width and height:

view.requestLayout()
kenzo
  • 211
  • 1
  • 9
  • Is it updated in nougat? because without calling `requestLayout()` also it is working on pre nougat devices – Ravi Dec 30 '16 at 10:26
  • I'm not sure about nougat just some thought about changing params. – kenzo Dec 30 '16 at 10:28
11

try this

view.setLayoutParams(new LinearLayout.LayoutParams(200, 120));

or this

ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = 130;
params.width = 130;
view.setLayoutParams(params);

hope it helps you out

Apoorv Mehrotra
  • 607
  • 5
  • 13