What is getGlobalVisibleRect ()?

Hi, I watched the developer code to enlarge the image, and I cannot figure out what this code should do:

final ImageView expandedImageView = (ImageView) findViewById( R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in image. // This step involves lots of math. Yay, math. final Rect startBounds = new Rect(); final Rect finalBounds = new Rect(); final Point globalOffset = new Point(); // The start bounds are the global visible rectangle of the thumbnail, // and the final bounds are the global visible rectangle of the container // view. Also set the container view offset as the origin for the // bounds, since that the origin for the positioning animation // properties (X, Y). thumbView.getGlobalVisibleRect(startBounds); findViewById(R.id.container) .getGlobalVisibleRect(finalBounds, globalOffset); startBounds.offset(-globalOffset.x, -globalOffset.y); finalBounds.offset(-globalOffset.x, -globalOffset.y); 

1) In particular, I'm not sure what to do getGlobalVisibleRect(finalBounds,globalOffset) ?

2) Besides, what exactly does startBounds.offset() and what does -globalOffset.x,-globalOffset.y even -globalOffset.x,-globalOffset.y ?

+10
source share
2 answers
  • getGlobalVisibleRect (finalBounds, globalOffset) returns the global position of the container view, and globalOffset is the offset of the entire screen. Thus, in this code globalOffset.x is 0, globalOffset.y is 75. (in my phone, 75 is the height of the status bar). If I call finalBounds.off (-globalOffset.x, -globalOffset.y), finalBounds has (0, 0, origin-0, origin-75), which means that finalBounds is a local coordinate, not global. The container view is important because it provides a base coordinate for two images.

  • Before calling startBounds.offset, startBounds has a global thumbView location. startBounds.offset () makes startBounds the local coordinate of the container view. finalBounds.offset () does the same. StartBounds and finalBounds now have the same relative coordinate, so making transitional animation easy.

  • If you use globalrect, the width / height will be wrong.

+7
source
  1. getGlobalVisibleRect (rect, offset) returns a boolean value indicating whether the view is visible in global coordinate.
  2. getGlobalVisibleRect (rect, offset), the first rectangle is the output parameter, which will be set to the visible rectangle of the view in the global coordinate.
  3. getGlobalVisibleRect (rect, offset), the second point is also an output parameter, which is set to the coordinate of the upper left point of the view. Note that, as shown below, this offset can have negative values, that is, the upper left viewpoint outside the screen.

Link: https://www.cnblogs.com/ai-developers/p/4413585.html

enter image description here

0
source

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


All Articles