View.getLayoutParams (). width does not work with nougat

I wrote code to dynamically determine the height and width of a view

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

It works great with nougat devices, but it doesn't work with nougat. It just takes the height and width as 0. Any changes after updating nougat?

Update:

However it works

1) when I use view.requestLayout() after setting the height and width
2) view.setLayoutParams(new LinearLayout.LayoutParams(200, 120));

So why does it work with pre nougat devices without using these 2 options?

+5
source share
2 answers

try it

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

or

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

hope this helps you

+7
source

Try calling after setting width and height :

 view.requestLayout() 
+4
source

Source: https://habr.com/ru/post/1262071/


All Articles