What exactly is getGlobalVisibleRect()?
getGlobalVisibleRect(finalBounds,globalOffset) returns the container's view global position, and globalOffset is the offset of the whole screen. So in this code, globalOffset.x is 0, globalOffset.y is 75.(in my phone, the 75 is the status bar height) If I call finalBounds.off(-globalOffset.x, -globalOffset.y), finalBounds has (0, 0 , origin-0, origin-75), meaning finalBounds is local coordinate not global. Container view is important, because it supplies basis coordinate for two images.
Before calling startBounds.offset, startBounds has global location of thumbView. startBounds.offset() does make startBounds to local coordinate of container view. finalBounds.offset() does the same thing. Now startBounds and finalBounds have same relative coordinate so that making transition animation is easy.
If use globalrect, width/height will be wrong.
- getGlobalVisibleRect(rect, offset) returns a boolean, stating whether the view is visible in the global coordinate.
- getGlobalVisibleRect(rect, offset), the first rect is a output parameter that will be set to the visible rectangle of the view in global coordinate.
- getGlobalVisibleRect(rect, offset), the second point is also an output parameter that is set to the coordinate of the left-top point of the View. Note as illustrated below, this offset can have negative values, meaning the left-top point of the view it's off the screen.
Reference: https://www.cnblogs.com/ai-developers/p/4413585.html