嗨,我一直在查看用于缩放 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
甚至意味着什么? 最佳答案
容器 View 很重要,因为它提供了两个图像的基本坐标。
startBounds.offset()确实使startBounds成为容器 View 的本地坐标。
finalBounds.offset()做同样的事情。现在,startBounds和finalBounds具有相同的相对坐标,因此制作过渡动画变得容易。