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

孤街醉人 提交于 2019-11-29 02:57:30

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!