Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between addonGlobalLayoutListener and addOnPreDrawListener

We know ViewTreeObserver is used to register listeners that can be notified of global changes in the view tree. There are two method defined in this class are addOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener listener) and addOnPreDrawListener(ViewTreeObserver.OnPreDrawListener listener). But the the purpose of these methods are not clearly understandable to me which described in the developer site. I tried to understand it and also searched in google but was unable to find clear picture about this topic. Any help is greatly handful for me.

like image 956
ashraful Avatar asked Oct 07 '15 08:10

ashraful


1 Answers

OnPreDrawListener

Gets called just before onDraw() method gets invoked. At this point, all views in the tree have been measured and given a frame. Therefore you can properly manipulate view in this callback

OnGlobalLayoutListener

This listener gets called: - when visibility state changes. In example when view has been drawn it becomes visible and this gets called. - when you addView state of view tree changes

like image 106
Adam Fręśko Avatar answered Sep 24 '22 06:09

Adam Fręśko