简体   繁体   English

如何在Android中查找捏缩放方向?

[英]How to find pinch zoom direction in android?

I have implemented pinch to zoom in my app.Normal zoom in and zoom out are working fine. 我已经实现了捏放大应用程序,正常的放大和缩小工作正常。 But if i zoom out while zooming in(without taking hands off from canvas) it is returning scale factor greater than 1 only. 但是,如果我在放大的同时缩小(不从画布上移开手),则它仅返回大于1的比例因子。 So i am not able to do he calculation properly.Is there any way to find out the zoom direction other than checking scalefactor value greater than 1.0 or not? 所以我不能正确地计算他,除了检查比例系数值是否大于1.0外,是否有其他方法可以找到缩放方向?

This works for me 这对我有用

private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener
{
  @Override
  public boolean onScale(ScaleGestureDetector detector)
  {
    mScaleFactor *= detector.getScaleFactor();
          // Don't let the object get too small or too large.
    mScaleFactor = Math.max(MIN_SCALE, Math.min(mScaleFactor, MAX_SCALE));
    //Log.d(TAG, "factor = " + mScaleFactor);

    updateTextSize();
    return true;
   }
}

For determining in/out direction you can compare 为了确定进/出方向,您可以比较

detector.getCurrentSpan();
detector.getPreviousSpan();

For determining horizontal/vertical direction you can compare 为了确定水平/垂直方向,您可以比较

detector.getCurrentSpanX();
detector.getCurrentSpanY();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM