After changing a property on a LayoutParams object, do I need to call setLayoutParams again?

后端 未结 1 500
星月不相逢
星月不相逢 2020-12-15 17:01

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)

相关标签:
1条回答
  • 2020-12-15 17:42

    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.

    0 讨论(0)
提交回复
热议问题