For example, for a TextView in Android you have to set the LayoutParams instead of the setWidth method.
TextView tv = new TextView(getContext());
LayoutParams params = new LayoutParams(100, LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(params);
But why? In the Android docs it says it would deliver the same result.
You have to use layoutParams because setting a different width or height can change all the positioning of the layout. All the view hierarchy has to accommodate to the new dimensions, the only way is changing the layout params. The parent then gets notificated and starts all the process of measuring the views of the children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With