Difference between addonGlobalLayoutListener and addOnPreDrawListener

We know ViewTreeObserver is used to register listeners who can be notified of global changes in the view tree. There are two methods defined in this class: addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) and addOnPreDrawListener(ViewTreeObserver.OnPreDrawListener listener) . But the purpose of these methods is incomprehensible to me, which is described on the developer's site. I tried to figure it out, and also searched on google, but could not find a clear picture about this topic. Any help helps me a lot.

+5
source share
1 answer
 OnPreDrawListener 

Gets a call immediately before the onDraw () method is called. At this point, all views in the tree were measured and set by a frame. Therefore, you can correctly manipulate the representation in this callback

 OnGlobalLayoutListener 

This listener is called: - when the visibility state changes. In the example, when the image was drawn, it becomes visible, and this is caused. - when you add the state of the tree of view changes

+4
source

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


All Articles