Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - difference between View.OnLayoutChangeListener and ViewTreeObserver.OnGlobalLayoutListener

According to the doc, the first is

Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing.

and the second is

Interface definition for a callback to be invoked when the global layout state or the visibility of views within the view tree changes.

///

But they seem pretty similar to me. I was even able to use both of them interchangeably. Can someone give me a practical example of the usage of them? Thanks

like image 204
user2062024 Avatar asked Aug 10 '16 21:08

user2062024


1 Answers

An OnLayoutChangeListener is a listener for a specific View and will trigger only when that View goes through a layout pass (i.e. onLayout() is called).

An OnGlobalLayoutListener watches the entire hierarchy for layout changes (so registering one of these on any View in a hierarchy will cause it to be triggered when any View in that hierarchy is laid out or changes visibility).

like image 197
Kevin Coppock Avatar answered Oct 24 '22 08:10

Kevin Coppock