View with horizontal and vertical pan/drag and pinch-zoom

前端 未结 9 2038
离开以前
离开以前 2020-11-28 22:56

Is it possible to have a view who supports horizontal and vertical pan/drag. On top of that, I want to be able to pinch to zoom and double tap to zoom. Does this view exists

9条回答
  •  心在旅途
    2020-11-28 23:26

    To get better permormance of Zooming in Alex's code add following changes

    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
    
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            mScaleFactor *= detector.getScaleFactor();
            if (detector.isInProgress()) {
                mFocusX = detector.getFocusX();
                mFocusY = detector.getFocusY();
            }
    
            mFocusX = (mFocusX + mLastTouchX)/2;  // get center of touch
            mFocusY = (mFocusY + mLastTouchY)/2;  // get center of touch
    
            mScaleFactor = Math.max(1f, Math.min(mScaleFactor, 2.0f));
            mScaleMatrix.setScale(mScaleFactor, mScaleFactor,mFocusX, mFocusY);
            mScaleMatrix.invert(mScaleMatrixInverse);
            invalidate();
            requestLayout();
    
            return true;
        }
    }
    

提交回复
热议问题