Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly is getGlobalVisibleRect()?

Tags:

java

android

Hi I been looking at the developer code for zoom a view and I can't seem to be figure out what this code suppose to 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's offset as the origin for the
// bounds, since that's 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) Specifically I am not so sure what getGlobalVisibleRect(finalBounds,globalOffset) suppose to do?

2) Also, what exactly does the startBounds.offset() suppose to do and what does -globalOffset.x,-globalOffset.y even mean?

like image 914
Wowzer Avatar asked Mar 04 '16 06:03

Wowzer


1 Answers

  1. getGlobalVisibleRect(rect, offset) returns a boolean, stating whether the view is visible in the global coordinate.
  2. getGlobalVisibleRect(rect, offset), the first rect is a output parameter that will be set to the visible rectangle of the view in global coordinate.
  3. 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

enter image description here

like image 148
Ian Wong Avatar answered Sep 18 '22 03:09

Ian Wong