Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java getGlobalVisibleRect()到底是什么?_Java_Android - Fatal编程技术网

Java getGlobalVisibleRect()到底是什么?

Java getGlobalVisibleRect()到底是什么?,java,android,Java,Android,您好,我一直在看zoom a view的开发人员代码,但我似乎不知道这段代码应该做什么: final ImageView expandedImageView = (ImageView) findViewById( R.id.expanded_image); expandedImageView.setImageResource(imageResId); // Calculate the starting and ending bounds for the zoomed-in i

您好,我一直在看zoom a view的开发人员代码,但我似乎不知道这段代码应该做什么:

 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) 具体来说,我不太确定
getGlobalVisibleRect(finalBounds,globalOffset)
应该做什么

2) 另外,
startBounds.offset()
究竟要做什么?甚至
-globalOffset.x,-globalOffset.y
都意味着什么

  • getGlobalVisibleRect(finalBounds,globalOffset)返回容器的视图全局位置,globalOffset是整个屏幕的偏移量。在这段代码中,globalOffset.x是0,globalOffset.y是75。(在我的手机中,75是状态栏的高度)如果我调用finalBounds.off(-globalOffset.x,-globalOffset.y),finalBounds有(0,0,origin-0,origin-75),这意味着finalBounds是局部坐标而不是全局坐标。 容器视图很重要,因为它为两幅图像提供了基本坐标。

  • 在调用startBounds.offset之前,startBounds具有thumbView的全局位置。 offset()会将startBounds设置为容器视图的局部坐标。 offset()也做同样的事情。现在,起始边界和最终边界具有相同的相对坐标,因此制作过渡动画很容易

  • 如果使用globalrect,则宽度/高度将错误

  • getGlobalVisibleRect(rect,offset)返回一个布尔值,说明视图在全局坐标中是否可见
  • getGlobalVisibleRect(rect,offset),第一个rect是一个输出参数,将设置为全局坐标中视图的可见矩形
  • getGlobalVisibleRect(rect,offset),第二个点也是一个输出参数,设置为视图左上点的坐标。注意,如下图所示,该偏移量可能有负值,这意味着视图的左上角不在屏幕上
  • 参考:


    哦,谢谢。我以前发现过这个链接,但仍然没有帮助,所以我问了这个问题。我还发现两个stackoverflow帖子试图回答这个问题,但答案非常模糊。@HaniyehKhaksar链接断了