Zac*_*ach 7 android canvas viewport scale pinchzoom
我有一个画布,我使用ScaleGestureDetector来放大我的Android应用程序.这是我到目前为止的代码:
//SCALING --------------------------------------------------
//get center of the viewport
int centerX = xLoc+((int)(screenWidth/2*scaleFactor));
int centerY = yLoc+((int)(screenHeight/2*scaleFactor));
scaleFactor /= detector.getScaleFactor();
// Don't let the object get too small or too large.
scaleFactor = Math.max(1.0f, Math.min(scaleFactor, maxScaleFactor));
//Make sure the viewport is repositioned
xLoc = centerX-((int)(screenWidth/2*scaleFactor));
yLoc = centerY-((int)(screenHeight/2*scaleFactor));
//-----------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
这非常适合放大和缩小画布.xLoc和yLoc表示我的视口的左上角与我绘制的一部分相关的整个图像.我对此代码的问题是,它放大到视口的中心.我希望能够使用detector.getFocuxX()和detector.getFocusY()来放大焦点,就像在Android浏览器中缩放一样.
基本上我需要调整视口的位置(xLoc和yLoc),以便它给出缩放到缩放手势焦点的外观.
我无法理解这一部分.如果有人知道如何在不使用画布矩阵转换的情况下做到这一点(我在发布之前已经在我发现的许多主题中使用过)我真的很感激!即使你可以把我指向做过类似事情的其他人.
单个onScale函数调用无法提供足够的信息来实现围绕明显焦点的缩放。您将需要保留上一次调用的值getFocusX()和getFocusY()来自上一次调用的值onScale,并使用它们来影响下一次调用中的缩放。
| 归档时间: |
|
| 查看次数: |
1299 次 |
| 最近记录: |