I have a View (containing an ad) that I need to scale to fit the screen width at a certain point in time (after the ad is loaded). So I have a method setHeight(myView)
A change to the layout params only take effect on the next layout pass.
requestLayout()
schedules a layout pass
setLayoutParams()
calls requestLayout()
as you have observed
Sometimes a layout pass is scheduled by some other means. For example, immediately after inflation the layout params have also been inflated and the measure/layout message has just been posted to the UI thread message queue for later processing.
So, to be safe, call requestLayout()
always after touching the layout params. setLayoutParams()
works, too, though it's not strictly necessary when modifying the params in-place.